r - ggplot2中的color和fill参数有什么区别?

标签 r ggplot2

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

将颜色更改为填充时,看不到有什么不同,例如:
ggmap(location) +
geom_density_2d(aes(long, lat), df) +
geom_point(aes(long, lat,**fill = special**),alpha = 0.5,data = df) 

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

最佳答案

通常,fill定义填充几何图形的颜色,而color定义轮廓几何图形的颜色(形状的“笔画”,以使用Photoshop语言)。

点通常只有一种颜色,没有填充,因为您知道,它们只是点。但是,point shapes 21–25 that include both a colour and a fill。例如:

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')

A ggplot with fill mapped to an aesthetic and colour fixed.

这是ggmap的示例,其中fillcolour均已设置(但未映射到美观):
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)

A ggmap with fixed colour and stroke.

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

关于r - ggplot2中的color和fill参数有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50557718/

相关文章:

r - 同一图中的多个变量

r - 如何避免矩阵计算中的双for循环

r - fread中的空白未被识别为NA

r - ggplot:删除图例中的NA因子水平

r - 如何在这个由几个不同的几何图形组成的ggplot中手动指定图例文本/颜色?

r - 按 ID 和结果分组,并取特定结果的最早最早日期并分配编号(即结果 1、结果 2)

r - 如何从 R 中将帮助内容写入文件?

r - 如何使用 ggplots 和 map 添加自定义图例

r - 如何在 R 中绘制带有预先计算统计数据的 ggplot2 箱线图?

r - 如何在嵌套箱线图中添加中间空间ggplot2