Home > Blockchain >  Is it possible to show standard deviation using geom_smooth in ggplot2?
Is it possible to show standard deviation using geom_smooth in ggplot2?

Time:12-01

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

enter image description here

So my questions are:

  1. Is it possible to display the running standard deviation using geom_smooth?
  2. 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))))) 

enter image description here

  • Related