I am trying to highlight a time series multiple times with the package ggplot2, I created a data.frame with the starting dates (xmin) and the ending dates (xmax) of all the highlights, but I'm getting: Error: Aesthetics must either be length one, or the same length as the dataProblems:xmin, xmax, ymin, ymax
the code is:
g.bottom <- ggplot(,aes(x =decimal_date(date), y =C$PE)) +
geom_rect(data=s,aes(xmin=decimal_date(xmin), xmax=decimal_date(xmax),ymin=ymin,ymax=ymax),
alpha=0.1, color="pink", fill="pink")+
geom_line() +
theme_classic() +
theme(plot.margin = unit(c(0,5,10,4),units="points"))+
labs(x="Fecha",y = "PE")
this is the data s:
xmin<-c("2011/07/28","2012/04/09","2012/04/16","2013/04/22","2014/12/08","2014/12/15","2014/12/18")
xmax<-c("2011/08/08","2012/04/12","2012/06/12","2013/04/26","2014/12/11","2014/12/16","2015/04/09")
ymin<- c(-Inf,-Inf,-Inf,-Inf,-Inf,-Inf,-Inf)
ymax<-c(Inf,Inf,Inf,Inf,Inf,Inf,Inf)
s<- data.frame(xmin,xmax,ymin,ymax)
transform(s, xmin=as.Date(xmin,format="%Y/%m/%d"))%>%
transform(xmax=as.Date(xmax,format="%Y/%m/%d"))->s
s
xmin xmax ymin ymax
1 2011-07-28 2011-08-08 -Inf Inf
2 2012-04-09 2012-04-12 -Inf Inf
3 2012-04-16 2012-06-12 -Inf Inf
4 2013-04-22 2013-04-26 -Inf Inf
5 2014-12-08 2014-12-11 -Inf Inf
6 2014-12-15 2014-12-16 -Inf Inf
7 2014-12-18 2015-04-09 -Inf Inf
and this is C
Date GSADF PE
1 26/01/2011 0.7990547 29.07
2 27/01/2011 0.7970526 29.20
3 28/01/2011 0.7947446 28.66
4 31/01/2011 0.7950117 29.05
5 01/02/2011 0.7931063 29.72
6 02/02/2011 0.7900929 29.92
library(lubridate) ; s$xmin <- ymd(s$xmin) ; s$xmax <- ymd(s$xmax)
– scoa