ggplot stat_smooth:改变多个乐队的外观

Tho*_*del 2 graphics r ggplot2

我正在尝试在同一图表中为不同级别的组var定制多个黄土图的外观.我查看了这篇文章,但无法使其发挥作用:

ggplot(iris, aes(x=Sepal.Length, y=Petal.Length, color=Species, linetype=Species)) + 
  stat_smooth(method = "loess")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我想改变每个乐队和乐队的颜色.

Jaa*_*aap 7

您可以使用例如scale_color_manual比例指定外观.在下面的例子中我也用override.aesguides得到一个不错的传说,以及:

ggplot(iris, aes(x=Sepal.Length, y=Petal.Length, color=Species, linetype=Species)) +
  stat_smooth(aes(fill=Species), method = "loess", size=1) +
  scale_color_manual(values = c("green","blue","red")) +
  scale_fill_manual(values = c("green","blue","red")) +
  scale_linetype_manual(values = c("dashed","dotted","solid")) +
  theme_bw() +
  guides(fill=guide_legend(override.aes = list(fill="white",size=1.2)))
Run Code Online (Sandbox Code Playgroud)

这给了:

在此输入图像描述

手动秤的其他替代品是huebrewer秤.