[英]Add +- 2 SE in regression line R
实现所需结果的一种选择是通过stat_smooth
手动添加置信stat_smooth
并使用after_stat
:
library(ggplot2)
ggplot(iris, aes(x = Petal.Length, y = Sepal.Width)) +
geom_smooth(method = lm, color = "black", se = FALSE) +
stat_smooth(aes(ymin = after_stat(y - 2 * se), ymax = after_stat(y + 2 * se)), geom = "ribbon", method = lm, fill = "grey60", alpha = .4) +
theme_bw()
#> `geom_smooth()` using formula 'y ~ x'
#> `geom_smooth()` using formula 'y ~ x'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.