ggplot2 timeseries chart with background shading
<p>I have an excel graph that I want to create in R.</p>

<p><a href="https://i.stack.imgur.com/q8ZXv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q8ZXv.png" alt="Excel Chart"></a></p>

<p>I tried recreating it with some dummy data</p>

<pre><code>a&lt;-rnorm(12)
a_ts&lt;-ts(a, start=c(2015, 1), frequency=12)
a_time&lt;-time(a_ts)
a_series&lt;-ts.union(ret=a_ts, date=a_time)
a_series_df&lt;-as.data.frame(a_series)

ggplot() +
geom_rect(data=data.frame(xmin=decimal_date(as.Date(c("2015-01-01"))),
xmax=decimal_date(as.Date(c("2015-05-31"))), ymin=-Inf, ymax=Inf),
aes(xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax), fill="pink", alpha=0.5) +
geom_line(data = a_series_df, aes(x=date,y=ret, color='blue')) +
theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) 
#this does not work
#scale_x_date(breaks = "1 month", minor_breaks = "1 month",   labels=date_format("%B-%d")) +
#scale_y_continuous(labels = scales::percent)
</code></pre>

<p>which looks like this </p>

<p><a href="https://i.stack.imgur.com/66HW3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/66HW3.png" alt="R version"></a></p>

<p>I am struggling with the date conversions and also setting the x and y origins to zero and getting the axis labels right, the last two lines of code work for non-date data points. I would also like to have a legend below the chart for series1, series2 and and entry for the shaded area.</p>

<p>Any help would be appreciated.</p>

<p>Update after applying the suggestions:</p>

<p><a href="https://i.stack.imgur.com/7OiD5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7OiD5.png" alt="X axis should be at y = 0 everything else should stay as it is, as in the excel"></a></p>