[英]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.