title: Using geom_rect for time series shading in R
body: <p>I am trying to shade a certain section of a time series plot (a bit like recession shading - similarly to the graph at the bottom of <a href="https://research.stlouisfed.org/tips/200511/recession_bars.pdf" rel="noreferrer">this article on recession shading in excel</a>). I have put a little, possibly clumsy, sample together to illustrate. 
  I first create a time series, plot it with ggplot2 and then want to use geom_rect to provide the shading. But I must get something wrong in the arguments.</p>
  
  <pre><code>a&lt;-rnorm(300)
  a_ts&lt;-ts(a, start=c(1910, 1), frequency=12)
  a_time&lt;-time(a_ts)
  a_series&lt;-ts.union(big=a_ts, month=a_time)
  a_series_df&lt;-as.data.frame(a_series)
  ggplot(a_series)+
    geom_line(mapping=aes_string(x="month", y="big"))+
    geom_rect(
      fill="red",alpha=0.5, 
      mapping=aes_string(x="month", y="big"), 
      xmin=as.numeric(as.Date(c("1924-01-01"))),
      xmax=as.numeric(as.Date(c("1928-12-31"))),
      ymin=0,
      ymax=2
      )
  </code></pre>
  
  <p>Note that I have also tried which also did not work.</p>
  
  <pre><code>geom_rect(
          fill="red",alpha=0.5, 
          mapping=aes_string(x="month", y="big"), 
          aes(
             xmin=as.numeric(as.Date(c("1924-01-01"))),
             xmax=as.numeric(as.Date(c("1928-12-31"))),
             ymin=0,
             ymax=2)
          )
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Wkq3O.png" alt="enter image description here"> </p>