ggplot2 timeseries chart with background shading
问题 I have an excel graph that I want to create in R. I tried recreating it with some dummy data a<-rnorm(12) a_ts<-ts(a, start=c(2015, 1), frequency=12) a_time<-time(a_ts) a_series<-ts.union(ret=a_ts, date=a_time) a_series_df<-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