gpt4 book ai didi

r - ggplot stat_smooth : change look of multiple bands

转载 作者:行者123 更新时间:2023-12-01 16:40:45 28 4
gpt4 key购买 nike

我正在尝试为组变量的不同级别自定义同一图表中多个黄土图的外观。我看了this发布,但无法使其正常工作:

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

enter image description here

我想更改每个波段和线条的颜色。

最佳答案

您可以指定外观,例如 scale_color_manual 比例。在下面的示例中,我还在 guides 中使用了 override.aes 来获得漂亮的图例:

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)))

这给出:

enter image description here

手动秤的其他替代方法是 huebrewer 秤。

关于r - ggplot stat_smooth : change look of multiple bands,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32800716/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com