【问题标题】:What is the difference between the color and fill argument in ggplot2?ggplot2中的颜色和填充参数有什么区别?
【发布时间】:2018-11-06 12:52:50
【问题描述】:
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


    【解决方案1】:

    这个问题再好不过了than done so here

    我没有将此标记为重复的唯一原因是您提出的问题略有不同。他们正在经历他们认为是错误的事情,而您正在经历您认为没有变化的事情。

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

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

    【讨论】:

      【解决方案2】:

      通常,fill 定义了一个几何图形填充的颜色,而 colour 定义了一个几何图形的轮廓颜色(形状的“笔触”,使用 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 的示例,其中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)
      

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

      【讨论】:

      • 您解释了 fillcolor 之间的区别,但仍然不清楚为什么 OP 在使用两者时得到相同的输出(请参阅问题中的代码 sn-ps)。是不是对于某些形状,两者都可以应用而输出没有任何差异?
      猜你喜欢
      • 1970-01-01
      • 2018-12-12
      • 2018-12-13
      • 2021-11-29
      • 2020-06-20
      • 1970-01-01
      • 2011-02-18
      • 2014-03-02
      • 2013-04-23
      相关资源
      最近更新 更多