【问题标题】:Change standard error color for geom_smooth更改 geom_smooth 的标准错误颜色
【发布时间】:2012-03-08 06:08:09
【问题描述】:

我正在使用 geom_smooth 绘制一些数据,并寻找一种方法来更改每条线的标准错误阴影的颜色以匹配该线(即,红线会将其标准错误阴影显示为红色)。

我查看了官方 ggplot2 文档以及 https://github.com/hadley/ggplot2/wiki/%2Bopts%28%29-List 的 opts() 列表。

感谢任何建议(或只是确认是否可行)。

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    您的(可以理解的)错误是认为您应该更改 color 而不是 fill。标准错误阴影本质上是用geom_ribbon 制作的,它们是一个二维区域,因此它们“填充”的“颜色”由fill 决定,而不是colour

    试试:

    geom_smooth(aes(...,fill = variable))
    

    其中变量与您映射到其他地方的颜色相同。

    【讨论】:

    • 如何处理交互?我正在使用ggplot( ... aes(... color=interaction(a,b))) + geom_smooth(... fill=interaction(a,b)),但出现错误:object 'a' not found'。这种可恶的“语言”中的经典不可预测的行为。
    【解决方案2】:

    如果您有多个组,您只需在ggplot(aes()) 中定义color = Varsgroup = Vars,然后在geom_smooth(aes(fill = Species)) 中定义额外的aes(fill = Vars)。 (Based on answer here)

    虚拟示例:

    # Make confidence intervals the same color as line by group
    ggplot(iris, aes(x = Sepal.Length, 
                     y = Sepal.Width, 
                     group = Species,
                     color = Species)) + 
      geom_point() + 
      geom_smooth(aes(fill = Species))  # additional `aes()` referencing to confidence interval as a `fill` not as a `color` 
    

    【讨论】:

      猜你喜欢
      • 2018-08-23
      • 1970-01-01
      • 2021-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多