Recession Shading


As an example we can plot the S&P 500 using the getshiller() function that we have described here.

This function gets the NBER recession data from your local cache of FRED data (see here for the function definition) and builds a data frame with the recession start and end dates. Then it adds a geom_rect() in blue with transparency (alpha=0.2) so you can see any lines or text through the shading.

Using this function it is straightforward to add recession shading to a univariate zoo time series by passing in the zoo time series plot and the ggplot plot object like this:

The end result looks like this:

recession_shading