im currently using the geom_smooth function to plot bacterial growth data.
I'm wondering if its possible to display the standard deviation as opposed to the confidence interval calculated by the standard error (as i think is the standard for this function)
Example:
p1<-mtcars %>%
ggplot(aes(x=mpg,cyl))
geom_smooth( size=2, span=1,color="tomato",fill="tomato")
So my questions are:
- Is it possible to display the running standard deviation using geom_smooth?
- If not, is there another way to achieve this?
Thanks a lot in advance!
CodePudding user response:
It is possible to do this nowadays directly inside geom_smooth
because we can work out the standard deviation from the calculated standard error inside after_stat
mtcars %>%
ggplot(aes(mpg, cyl))
geom_smooth(size = 2, span = 1, color = "tomato", fill = "tomato",
aes(ymax = after_stat(y se * sqrt(length(y))),
ymin = after_stat(y - se * sqrt(length(y)))))