ggplot2中的color和fill参数有什么区别? [英] What is the difference between the color and fill argument in ggplot2?

查看:1564
本文介绍了ggplot2中的color和fill参数有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ggmap(location) +
geom_density_2d(aes(long, lat), df) +
geom_point(aes(long, lat,**color = special**),alpha = 0.5,data = df) 

当我更改填充颜色时,看不到有什么不同,例如:

I can not see what is different when I change color to the fill, like:

ggmap(location) +
geom_density_2d(aes(long, lat), df) +
geom_point(aes(long, lat,**fill = special**),alpha = 0.5,data = df) 

这两个参数之间的主要区别是什么?

what is the main difference between those two arguments?

推荐答案

通常,fill定义填充的颜色,而 colour 定义轮廓线轮廓线的颜色(形状的笔触",以使用Photoshop语言).

Generally, fill defines the colour with which a geom is filled, whereas colour defines the colour with which a geom is outlined (the shape's "stroke", to use Photoshop language).

通常只有一种颜色,没有填充,因为您知道,它们只是点.但是,包含颜色和填充的点形21–25 .例如:

Points generally only have a colour and no fill, because, y'know—they're just points. However, point shapes 21–25 that include both a colour and a fill. For example:

library(tidyverse)
df = data_frame(x = 1:5, y = x^2)
ggplot(df) +
  geom_point(
    aes(x, y, fill = x),
    shape = 21, size = 4, colour = 'red')

这是ggmap的示例,其中同时设置了fillcolour(但未映射到美学):

Here's an example with ggmap, where both fill and colour are set (but not mapped to aesthetics):

library("ggmap")

us = c(left = -125, bottom = 25.75, right = -67, top = 49)
map = get_stamenmap(us, zoom = 5, maptype = "toner-lite")
df2 = data_frame(
  x = c(-120, -110, -100, -90, -80),
  y = c(30, 35, 40, 45, 40))

ggmap(map) +
  geom_point(
    aes(x, y), data = df2,
    shape = 21, fill = 'blue', colour = 'red', size = 4)

但是,除非您使用这些特殊形状,否则如果使用点,请给它一个colour,而不是fill(因为大多数点没有一个).

But unless you're using those special shapes, if you use a point, give it a colour, not a fill (because most points don't have one).

这篇关于ggplot2中的color和fill参数有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆