how do I add recession bars in a ggplot

Hi, I am looking to create a graph showing unemployment over the years and then adding in bars in the background of the plot highlighting periods of recession?

What code would I use for this? And do i need to use dates within the code?

Code I have tried is

ggplot(unemployment_data, aes(x=year, y=unemployment))+

However, I am unsure if how I use geom_rect() and if that is the correct function to use? Similarly, when I go to plot that ggplot as above, for some reason geom_line() doesnot work at appears with the error message
"geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic" - how do I fix this?

Thanks for any help

Could you make a reprex (Reproducible Example) of the dataframe you want to use for the ggplot?

With that I could be able to help.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

Easy way for future reference to make a reprex is to just put ``` before the start code.

Gonna take a look at it with the data you gave.

Year Unemployment
111  n
111  n
111  n

#Ideally this though
year <- c("111", "111", "111")
unemployment <- c("n", "n", "n")

dataframe looks like this:
Year unemployment rate
1971 4
1972 4.1
1973 4.5
1974 4.3
1975 4.8
1976 5.0
1977 5.6
1978 5.2
1979 4.3
1980 4.0

and it continues all the way to 2020