[R] Are there equivalents to xblocks or rect that can be used with plot.xts?
ggrothendieck at gmail.com
Wed Nov 9 14:07:36 CET 2011
On Wed, Nov 9, 2011 at 4:33 AM, thierrydb <thierrydb at gmail.com> wrote:
> I would like to add vertical shaded blocks in plot.xts graphs (like recession
> periods in FRED graphs)
> The reason I use plot.xts instead of plot.zoo is that I like the fact that
> the grid is automatically aligned with major ticks in plot.xts.
> xblocks() and rect() do not seem to work with plot.xts (only with plot.zoo).
> Are there any alternative methods that work with plot.xts?
Just suppress one or both axes and then draw them with their grid in
exactly the same way that you would in R classic graphics. Its only
one or two extra statements depending on whether you want one or both:
z <- zooreg(1:25, Sys.Date())
plot(z, type = "o", xaxt = "n", yaxt = "n")
abline(v = Axis(time(z), side = 1), lty = 2, col = grey(.5)) # X
abline(h = Axis(coredata(z), side = 2), lty = 2, col = grey(.5)) # Y
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
email: ggrothendieck at gmail.com
More information about the R-help