I have data for which I need to calculate and plot the mean and a 95% confidence limits, but I don't know where I'm going wrong with my code. The data is grouped by year and I thought about using stat_smooth() to draw a confidence interval region, but I just can't get it off the ground. If I try I get an error:
Error: geom_path: If you are using dotted or dashed lines, colour, size and linetype must be constant over the line
library(ggplot2)
library(dplyr)
dat <- data.frame(cbind(rep(1:10,10),rnorm(100,600,sd=100),rnorm(100,400,sd=50),rnorm(100,700,sd=100)))
colnames(dat) <- c("year","S4","S5","S6")
df<-data.frame(dat)
ggplot(df)+
geom_line(aes(x=year, y=mean(df$S4),colour=year)) +
geom_line(aes(x=year, y=quantile(df$S4,0.95),colour=year),linetype="dotted") +
geom_line(aes(x=year, y=quantile(df$S4,0.05),colour=year),linetype="dotted")
