【发布时间】:2020-02-20 15:07:08
【问题描述】:
我想在 R 中使用 ggplot2 包创建直方图,并添加垂直线以显示均值-sd 和均值 + sd。
我正在使用以下代码
iris %>%
ggplot(aes(Sepal.Length)) + geom_histogram() + theme_bw() +
geom_vline(xintercept = mean(iris$Sepal.Length) - sd(iris$Sepal.Length), linetype = "dashed") +
geom_vline(xintercept = mean(iris$Sepal.Length), linetype = "solid") +
geom_vline(xintercept = mean(iris$Sepal.Length) + sd(iris$Sepal.Length), linetype = "dashed")
完美运行。有什么方法可以为每个组添加不同的颜色吗?
例如,低于均值的分数 - 橙色的 sd 和高于均值 + 红色的 sd 的分数。
先谢谢你了。
【问题讨论】: