ggplot2中的颜色和填充参数有什么区别?

问题描述 投票:3回答:2
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) 

这两个论点之间的主要区别是什么?

r ggplot2
2个回答
6
投票

通常,fill定义填充geom的颜色,而color定义用于绘制geom的颜色(形状的“stroke”,使用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(因为大多数点没有一个)。


2
投票

这不能更好地回答than done so here

我没有将此标记为重复的唯一原因是您要求稍微不同的问题。他们正在体验他们认为是一个错误的东西,你正在经历你认为没有变化的东西。

总之,您可以为geom_point选择几种形状,其中只有一些具有填充和颜色参数。

一般来说,fill会改变形状内的颜色,而colour会改变轮廓。

© www.soinside.com 2019 - 2024. All rights reserved.