I have this 3 time series:
a<-rnorm(357)
b<-rnorm(357)
c<-rnorm(357)
a_ts<-ts(a, start=c(1980, 1), frequency=12)
b_ts<-ts(b, start=c(1980, 1), frequency=12)
c_ts<-ts(c, start=c(1980, 1), frequency=12)
a_time<-time(a_ts)
a_series<-ts.union(month=a_time,a=a_ts)
a_series_df<-as.data.frame(a_series)
a_series_df["b"] <- b_ts
a_series_df["c"] <- c_ts
To use ggplot
function i melted
it:
melted = melt(a_series_df, id.vars="month")
The plot goes well:
ggplot(data=melted, aes(x=month, y=2*value)) + geom_line(aes(colour = variable))
But when i want a shed plot between these intervals below, it shows this error message:
shade = data.frame(x1=c(1980.333 ,2009.167), x2=c(2007.333 ,2009.667), y1=c(0,3), y2=c(0,4))
ggplot(data=melted, aes(x=month, y=2*value)) + geom_line(aes(colour = variable))+
geom_rect(data=shade, mapping=aes(xmin=x1, xmax=x2, ymin=y1, ymax=y2), color='grey', alpha=0.2)
Error in eval(expr, envir, enclos) : object 'month' not found
What am I missing?