nberShade.ggplot {tis} | R Documentation |
nberShade.ggplot
is a method for shading recession areas
in a plot of class ggplot
. It calls
nberDates
to get x coordinates for the areas to be shaded
and then passes those coordinates along with its own arguments to
geom_rect
to do the shading. It may also draw a vertical
line at the appropriate location if openShade
is false and
its xrange
is of an appropiate size.
## S3 method for class 'ggplot': nberShade(gg = ggplot2:::last_plot(), fill = "grey80", color = NA, size = 0.5, alpha = 0.5, xrange = NULL, openShade = TRUE, ...)
gg |
A ggplot object that contains a mapping of y to its data .
The default is to use the last ggplot object that was plotted. |
fill |
color to shade recessionary periods, passed to geom_rect . |
color |
The default (NA ) omits borders on the shaded
regions. Alternatively, specify a border color. Passed to geom_rect |
size |
A number specifying how thick should the border lines be. Passed to geom_rect |
alpha |
A number specifying how transparent the shaded regions should be. Passed to geom_rect |
xrange |
Horizontal range over which recession shading should be
drawn. The default value NULL uses the entire range of the
recession dates. xlim and scale_x_date are convenient
ggplot2 functions to afterwards restrict the plot to a more sensible range.
|
openShade |
governs how nberShade handles the case where
the last row of the matrix returned by
nberDates has an NA in the "End" column, indicating
that the end date of the most recent recession is not yet known.
If TRUE and xrange has been specified and extends far enough
into the future it will replace the NA with xrange[2] .
Else if openShade is TRUE and xrange is NULL then it will
replace the NA with Sys.Date() . If openShade is FALSE then
nberShade will draw a vertical line at the start of the
most recent recession. |
... |
not used, present only to match generic |
Returns a ggplot
object.
Recessions are dated by the Business Cycle Dating Committee of the National Bureau of Economic Research.
National Bureau of Economic Research. http://www.nber.org.
geom_rect
, nberDates
, nberShade
## Not run: require("ggplot2") ggp <- ggplot(aes(x=date, y=unemploy), data=economics) nberShade( ggp ) + xlim(as.Date("1967-01-01"), Sys.Date()) + opts(legend.position="none") + geom_line() + theme_bw() nberShade( ggp, fill = "yellow", color = "pink", xrange = c("1969-01-01", "2008-02-01"), openShade = FALSE) + opts(legend.position="none") + geom_line(size=1) + theme_bw() ## End(Not run)