Skip to content

Using dates on axis with Grid plots

1 message · Deepayan Sarkar

#
On Thu, May 26, 2011 at 4:34 AM, Paul Murrell <p.murrell at auckland.ac.nz> wrote:
The (newish) pretty.POSIXt method makes this relatively painless:


foo <- as.POSIXct(Sys.Date() + c(0, 365, -365))

grid.newpage()
pushViewport(
   plotViewport(
       c(5, 5, 4, 2),
       xscale = as.numeric(range(foo)),
       yscale = c(0,30)
   )
)

grid.rect()
p <- pretty(foo)
grid.xaxis(at = p, label = attr(p, "labels"))

p <- pretty(foo, n = 2)
grid.xaxis(at = p, label = attr(p, "labels"), main = FALSE)

-Deepayan