I have a dataframe "test" with column1 - dates (timelines), column2 - 1 OR 0 variable (specific periods of time - named binary) and column3 (GDP) - GDP growth rate. I would like to plot a ggplot with GDP growth rate over time and additionally, I would like to shade areas that have 1 in column 2. Lets say dates between 1972 - 1977 and 1990 - 1992 all have 1 in column2 and I would like this timespan to be shaded in grey on the chart. Formerly, I created a data table such as:
"Peak, Trough
1972-01-01, 1977-01-01
1990-01-01, 1992-01-01"), sep=',',
colClasses=c('Date', 'Date'), header=TRUE)
and used it
ggplot(data=filter(test),aes(x=test$timelines,y=test$GDP))+
geom_rect(data=filter(period.df,year(Peak)>1959), inherit.aes=F, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='darkgray')
but now the binary (column2) variable can change and I need to supply the ggplot an appropriate timespans so that it can shade areas marked with 1. Thank you!!