Ich habe diese drei Zeitreihen:Mit ggplot und geom_rect
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
ggplot
Funktion nutzen zu können ich es melted
:
melted = melt(a_series_df, id.vars="month")
Das Grundstück geht gut:
ggplot(data=melted, aes(x=month, y=2*value)) + geom_line(aes(colour = variable))
Aber wenn Ich möchte ein Shed-Diagramm zwischen diesen Intervallen unten, es zeigt diese Fehlermeldung:
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
Was fehlt mir?