Predicting with ggplot

Hi there,

Created a predictive plot with ggplot2, as follows:

pred.int <- predict(model, interval = "prediction")
mydata <- cbind(df_linelist_yearweeks, pred.int)
# 2. Regression line + confidence intervals
library("ggplot2")
p <- ggplot(mydata, aes(weeknumber, cm_cases)) +
  geom_point() +
  stat_smooth(method = lm)
# 3. Add prediction intervals
#p + geom_line(aes(y = lwr), color = "red", linetype = "dashed")+
#    geom_line(aes(y = upr), color = "red", linetype = "dashed")
#4. Print just the plot. 
p

The prediction intervals are not working, unfortunately, and I'd like to see the plot when cm_cases=1000.

Hi @graceahey,
I think you need to specify the x values in the line plotting:

p + geom_line(aes(y = lwr, x=weeknumber)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.