Home > Blockchain >  In ggplot2,specify values to use for geom_smooth() confidence interval (similar to geom_errorbar)
In ggplot2,specify values to use for geom_smooth() confidence interval (similar to geom_errorbar)

Time:06-10

I am plotting temperature values over the course of a year using geom_smooth(). I have daily min, max, and mean temperatures, and I would like to display the mean as a line, and then the min and max like you would display a confidence interval. There is a se = T argument to geom_smooth(), and I am wondering how I can supply variables to use as the "confidence interval." I know you can do this with box plots with geom_errorbar(), and I'm hoping there is a similar version for line plots.

I would like my plot to look like the results of this, but using the max and min values to display the confidence interval.

mean <- runif(365, min = 10, max = 25)
max <- runif(365, min = 26, max = 35)
min <- runif(365, min = 0, max = 9)

temp <- data.frame(day = 1:365, mean = mean)

ggplot(data = temp, aes(x = day, y = mean))  
  geom_smooth()

Thanks!

CodePudding user response:

EDIT #2: See bottom for smoothed ribbon. Adopted from enter image description here

Of if you mean you want to use the min and max values directly as your shaded range:

ggplot(data = temp, aes(x = day, y = mean))  
  geom_ribbon(aes(ymin = min, ymax = max),
              alpha = 0.1)  
  geom_smooth(se = FALSE)

enter image description here


Adopted from enter image description here

  • Related