Skip to content
Prev 247464 / 398503 Next

xyplot: modify axis tick marks

On Sun, Jan 16, 2011 at 8:01 AM, Kang Min <ngokangmin at gmail.com> wrote:
First we read in the data using zoo's "yearmon" class for the index:
yearmon variables are stored as year plus a fraction to indicate the
month such that January's fraction is zero so picking out the January
indexes using cycle(z) == 1 gives the years.  With lattice we need to
convert that to numeric years but its unnecessary using classic
graphics.

library(zoo)
z <- read.zoo("myfile.dat", header = TRUE, FUN = as.yearmon, format = "%b%Y")

# using xyplot.zoo and lattice
library(lattice)
xyplot(z, scales = list(x = list(at = as.numeric(time(z))[cycle(z) == 1])))

# using plot.zoo and classic graphics
plot(z, xaxt = "n")
axis(1, time(z)[cycle(z) == 1])