title: How to shade a certain area of time series plot using geom_rect?
body: <p>I'm trying to shade a certain area of time series plot using <code>geom_rect</code>.</p>
  
  <p>I used the code below to create the time series plot</p>
  
  <pre><code>library(ggplot2)
  
  set.seed(123)
  date &lt;- as.Date(seq(as.Date("2014-01-01"), as.Date("2015-12-31"), by = 1), format="%Y-%m-%d")
  a &lt;- runif(730, 3000, 120000)
  df &lt;- data.frame(date, a)
  
  ggplot() +
      geom_line(data = df, aes(x = date, y = a))
  </code></pre>
  
  <p>I tried to create the rectangle using <code>geom_rect</code> <a href="https://stackoverflow.com/questions/29648907/using-geom-rect-for-time-series-shading-in-r"><strong>following the answer to this question</strong></a></p>
  
  <pre><code>library(lubridate)
  rectangle &lt;- data.frame(xmin = decimal_date(as.Date(c("2014-10-01"))),
                          xmax = decimal_date(as.Date(c("2015-02-01"))),
                          ymin = -Inf, ymax = Inf)
  ggplot() +
      geom_line(data = df, aes(x = date, y = a)) +
      geom_rect(data = rectangle, aes(xmin=xmin, xmax = xmax, ymin = ymin, ymax = ymax),
          fill = "red", alpha = 0.5)
  </code></pre>
  
  <p>I got this error</p>
  
  <blockquote>
    <p>Error: Invalid input: date_trans works with objects of class Date only</p>
  </blockquote>
  
  <p>Any suggestions how to fix that would be appreciated.</p>