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')
这是
ggmap
的示例,其中fill
和colour
均已设置(但未映射到美观):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
(因为大多数点都没有一个)。
关于r - ggplot2中的color和fill参数有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50557718/