title: Change color background in ggplot2 - R by specific Date on x axis
body: <p>I want to change the color of the background in my scatterplot based on a specific date (on X axis). Ma dates range from 23th june 2017 to 6th december 2017. I want the background green from 23th june to 31th august, and all the rest red.</p>
  
  <p>I've tried with this script here <a href="https://stackoverflow.com/questions/33322061/change-background-color-panel-based-on-year-in-ggplot-r">Change background color panel based on year in ggplot R</a> but it doesn't work (I've never used ggplot2 before honestly).
  The date variable is POSIXct format. This is the script I used with the error that R gives me:</p>
  
  <pre><code>&gt; ggplot() + geom_point() + 
  geom_rect(aes(xmin = as.Date("2017-06-23"),xmax = as.Date("2017-08-31"),ymin = 0, ymax = Inf),
            fill="green", 
            alpha = .2)+
  geom_rect(aes(xmin = as.Date("2017-09-01"),xmax = as.Date("2017-12-06"),ymin = 0, ymax = Inf),
            fill="red", 
            alpha = .2)
  Errore: Invalid input: time_trans works with objects of class POSIXct only
  </code></pre>
  
  <p>What is wrong (or missed) with this script?</p>
  
  <p>If it can be useful this is the <code>str()</code> of my dataset <code>data</code></p>
  
  <pre><code>str(data)
  'data.frame':   420 obs. of  2 variables:
   $ UTC.Date        : POSIXct, format: "2017-07-01" "2017-08-01" "2017-09-01" "2017-10-01" ...
   $ Mean.elevation  : num  1353 1098 905 747 1082 ...
  </code></pre>
  
  <p>Here there are some data if you want to try (first 30 lines of my dataset):</p>
  
  <pre><code>UTC.Date           Mean.elevation
  1  2017-07-01      452.88224
  2  2017-08-01      499.03211
  3  2017-09-01      600.52692
  4  2017-10-01      554.38923
  5  2017-11-01      424.03798
  6  2017-07-02      697.89243
  7  2017-08-02      404.75938
  8  2017-09-02      104.60064
  9  2017-10-02     2194.45778
  10 2017-11-02      314.21575
  11 2017-12-02      464.44365
  12 2017-07-03      876.20422
  13 2017-08-03      308.53507
  14 2017-09-03      377.45005
  15 2017-10-03      805.73900
  16 2017-11-03      405.05043
  17 2017-07-04      939.72697
  18 2017-08-04      508.95055
  19 2017-09-04      763.68243
  20 2017-10-04       64.56294
  21 2017-11-04      783.69125
  22 2017-07-05      505.33392
  23 2017-08-05     1164.36239
  24 2017-09-05     1534.99598
  25 2017-10-05       12.05559
  26 2017-11-05     1209.14527
  27 2017-07-06      167.01947
  28 2017-08-06      451.23450
  29 2017-09-06      989.66036
  30 2017-10-06       54.97960
  </code></pre>