ymdXy
returns a list of x and y coordinates that can be fed
to polygon
to draw NBER shadings on the current plot.
If the last row of the ymds
argument has a Start entry but an "NA"
End entry and openShade
is FALSE
, the returned list will
not have coordinates for the last row, but will instead include a
vLine element that gives the x coordinate of the last Start. If
openShade
is TRUE
(the default), the list includes x
and y coordinates for the last row of ymds
, using the second
element of the horizontal range determined by the xrange
parameter as its end time.
ymdShade
shades date ranges on the current tisPlot.
on the current plot. It calls ymdXy
to get x and y
coordinates for the areas to be shaded and then passes those
coordinates along with its own arguments to polygon
to
do the shading. It also draws a vertical line at the appropriate
location if the list returned by ymdXy
has a vLine element.
ymdShade(ymds, col = grey(0.8), border = FALSE, xpd = FALSE,
xrange = NULL, openShade = TRUE, ...)
ymdXy(ymds, xrange = NULL, openShade = TRUE)
a matrix of yyyymmdd dates with two columns named 'Start'
and 'End' that specifies the date ranges to be shaded.
nberDates()
produces a suitable matrix.
color to shade recessionary periods
the default (FALSE
) omits borders on the shaded
regions. TRUE
draws borders in the foreground color.
Alternatively, specify a border color.
should clipping take place?
other args passed to polygon
horizontal range over which recession shading should be
drawn. The default value NULL
uses the entire range of the
plot. Note however the tisPlot
uses the range of the data,
which will generally differ the plot range unless the tisPlot
parameters leftExpandBy
and rightExpandBy
are zero.
You can force tisPlot
to use the plot range by setting the
parameter nberArgs = list(xrange = NULL)
.
governs how ymdXy
and consequently
ymdShade
handle the case where the last row of the ymds
matrix has an NA
in the "End" column, indicating that the end
date of the most recent shaded period is not known.
As described above, ymdXy
returns a list. ymdShade
does not return anything useful.
# NOT RUN {
require("datasets")
plot(presidents, type='n', ylab="Presidents approval rating")
ymdShade(nberDates())
lines(presidents)
# }
Run the code above in your browser using DataLab