geom_recessions
adds shaded recession bars to a time-series ggplot2 chart
(a chart with a date object in the x-axis.) These recession bars correspond to all
NBER-dated recessions
that overlap with the date range of the chart.
By default, each recession bar will be drawn as a light blue rectangle
spanning the entirety of the y-axis plus a dark blue rectangle drawn only over
the topmost part of the chart.
Usage
geom_recessions(
fill = "#BDCFDE",
alpha = 1,
draw_top_bar = TRUE,
top_fill = "#236192",
top_alpha = 1,
method = c("midpoint", "trough", "peak")
)
Arguments
- fill
The color of the main bar; defaults to a light blue tint.
- alpha
The alpha transparency of the main bar; defaults to 1.0 (totally opaque).
- draw_top_bar
Whether to draw the top bar or not.
- top_fill
The color of the top bar; defaults to a dark blue tint.
- top_alpha
The alpha transparency of the top blue bar; defaults to 1.0 (totally opaque).
- method
The method or interpretation used to show the recession data. Defaults to the midpoint method.
Implementation details
Internally, geom_recessions
works by adding a GeomRecessions
ggplot2::ggproto object, which inherits from ggplot2::Geom. It
replaces the setup_data
and draw_panel
methods in order to
load the recession data and draw the bars respectively.
Further, the actual drawing is done by two grid::rectGrob
objects, for the main blue bar and the top dark blue bar.
Inspiration and alternative implementations
This function is heavily inspired on geom_recessions
from the CMAPPLOT package.
Alternative methods used to show recession data
As discussed in the St. Louis Fed FRED website (HTML version), there are multiple interpretations or methods for shading recessions. First, the "midpoint" method shades both the peak and trough months. It is used by the Fed Board and St. Louis Fed for their publications. Second, the "trough" method shades the trough month but not the peak month. It is used in FRED graphs. Lastly, the "peak" method shades the peak month but not the trough month.