title: Plotting of cumulative data of multiple year in R
body: <p>I have daily rainfall data which I have converted to yearwise cumulative value using following code</p>
  <pre><code>library(seas)
  library(data.table)
  library(ggplot2)
  
  #Loading data
  data(mscdata)
  dat &lt;- (mksub(mscdata, id=1108447))
  dat$julian.date &lt;- as.numeric(format(dat$date, &quot;%j&quot;))
  DT &lt;- data.table(dat)
  DT[, Cum.Sum := cumsum(rain), by=list(year)]
  
  df &lt;- cbind.data.frame(day=dat$julian.date,cumulative=DT$Cum.Sum)
  </code></pre>
  <p>But when I am trying to plot, it gives me weired output like</p>
  <pre><code>#Plotting using base R
  df &lt;- df[order(df[,1]),]
  plot(df$day, df$cumulative, type=&quot;l&quot;, xlab=&quot;Day&quot;, ylab=&quot;Cumulative rainfall&quot;)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/kc6aI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kc6aI.png" alt="enter image description here" /></a></p>
  <p>Same I am getting using <code>ggplot2</code> also like</p>
  <pre><code>#Plotting using ggplot2
  ggplot(df, aes(x = day, y = cumulative)) + geom_line()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/6pXbG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6pXbG.png" alt="enter image description here" /></a></p>
  <p>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</p>
  <p><a href="https://i.stack.imgur.com/xIg6F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xIg6F.png" alt="enter image description here" /></a></p>
  <p>How to achieve this?</p>