Question

This time I am struggling to adjust the X axis in a two-screen zoo plot. Here's an example, inspired from a previous post:

x.Date <- as.Date(paste(rep(2003:2004, each = 12), rep(1:12, 2), 1, sep = "-"))
x <- zoo(data.frame(rnorm(24), rnorm(24)), x.Date)

then when I plot without X axis and add an axis separately

plot(x, xaxt = "n")
axis(1, at = time(x), labels = FALSE)

nothing happens (also with more complex versions of the axis, for example with labels)... What am I doing wrong?

Many thanks

Benoit

Was it helpful?

Solution

One idea is to use xyplot.zoo the lattice version of plot.zoo. Very easy to customize your x-axis using scales parameter.

 library(lattice)
 xyplot(x, 
   scales=list(
     x=list(  at=time(x),
              format='%y-%m')
   ))

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top