更改geom_smooth的标准错误颜色

Bry*_*yan 14 r ggplot2

我正在使用geom_smooth绘制一些数据并寻找一种方法来更改每行的标准错误着色的颜色以匹配该行(即,红线会使其标准错误以红色着色).我查看了官方ggplot2文档以及https://github.com/hadley/ggplot2/wiki/%2Bopts%28%29-List上的opts()列表.任何建议(或只是确认是否可能)表示赞赏.

jor*_*ran 28

你的(可理解的)错误是认为你应该改变颜色而不是填充颜色.标准错误阴影geom_ribbon基本上是,并且它们是2d区域,因此它们"填充"的"颜色"由fill,而不是colour.

尝试:

geom_smooth(aes(...,fill = variable))
Run Code Online (Sandbox Code Playgroud)

其中变量与您在其他位置映射到颜色的变量相同.


may*_*cca 5

如果您有多个组,您可以简单地定义color = Varsgroup = Varsinside ggplot(aes()),然后aes(fill = Vars)在 内添加其他组geom_smooth(aes(fill = Species))。(基于这里的答案

虚拟示例:

# 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` 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述