I have been trying to build a bar chart for GDP growth in UK and overlay it with a recession bands. I can do what is necessary with the bar plot but the moment I overlay with the recession bands, i get an error that a variable cannot be found.
uk.recessions.df <- read.table(textConnection(
"Peak, Trough
1857-06-01, 1858-12-01
1867-06-01, 1869-12-01
1873-10-01, 1879-03-01
1882-03-01, 1885-05-01
1887-03-01, 1888-04-01
1890-07-01, 1891-05-01
1893-01-01, 1894-06-01
1895-12-01, 1897-06-01
1919-03-01, 1921-07-01
1930-01-01, 1931-12-01
1956-04-01, 1956-08-01
1961-07-01, 1962-01-01
1973-09-01, 1974-04-01
1975-04-01, 1975-10-01
1980-01-01, 1981-04-01
1990-07-01, 1991-09-01
2008-04-01, 2009-07-01
2020-01-01, 2020-07-01"), sep=',',
colClasses=c('Date', 'Date'), header=TRUE)
uk.recessions.trim.df <- subset(uk.recessions.df, Peak >= min(tbl.QQGDP$Date))
tbl.data <- tbl.QQGDP %>%
mutate(Value = GDPGrowth < 0)
p <- ggplot(data = tbl.data, aes(x = Date, y = GDPGrowth, fill = Value)) +
geom_col(position = "identity", colour = "black", size = 0.25) +
scale_fill_manual(values = c("#85225f","#dbab01"), guide = FALSE) +
theme_tq()
p <- p +
geom_rect(data = uk.recessions.trim.df,
aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = Inf),
fill = "grey", alpha = 0.5)
p
The error i get is
Error in FUN(X[[i]], ...) : object 'GDPGrowth' not found
I am cannot figure out what i am doing wrong. Any help (even if to tell me off for a silly mistake!!) will be greatly appreciated.