I have daily rainfall data which I have converted to yearwise cumulative value using following code
library(seas)
library(data.table)
library(ggplot2)
#Loading data
data(mscdata)
dat <- (mksub(mscdata, id=1108447))
dat$julian.date <- as.numeric(format(dat$date, "%j"))
DT <- data.table(dat)
DT[, Cum.Sum := cumsum(rain), by=list(year)]
df <- cbind.data.frame(day=dat$julian.date,cumulative=DT$Cum.Sum)
But when I am trying to plot, it gives me weired output like
#Plotting using base R
df <- df[order(df[,1]),]
plot(df$day, df$cumulative, type="l", xlab="Day", ylab="Cumulative rainfall")
Same I am getting using ggplot2
also like
#Plotting using ggplot2
ggplot(df, aes(x = day, y = cumulative)) + geom_line()
But I want to get lines for every year may be in grey colour and mean value over the years in red colour like the following figure
How to achieve this?