thierrydb
2011-Nov-09 09:33 UTC
[R] Are there equivalents to xblocks or rect that can be used with plot.xts?
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? Thanks. -- View this message in context: http://r.789695.n4.nabble.com/Are-there-equivalents-to-xblocks-or-rect-that-can-be-used-with-plot-xts-tp4019191p4019191.html Sent from the R help mailing list archive at Nabble.com.
Gabor Grothendieck
2011-Nov-09 13:07 UTC
[R] Are there equivalents to xblocks or rect that can be used with plot.xts?
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: library(zoo) 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. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com