[R] problem with chron scales in lattice

Waichler, Scott R Scott.Waichler at pnl.gov
Wed Jun 1 19:12:35 CEST 2005


I can't get the scales parameter in xyplot of lattice to work as I
expected.  I'm using R-2.1.0 and lattice 0.11-8.  There should be year
labels from 1992 to 2004 for the x axis in the plot below, but instead
only a few of them appear, and in the wrong spots, as if the coordinate
system has changed after finishing with the panel function.

library(chron)
library(lattice)

# vertical grid lines at start of each year
startdate <- "1/1/1992"
enddate   <- "1/1/2005"
startdatetime <- chron(dates=startdate, times="00:00:00")
enddatetime <- chron(dates=enddate, times="00:00:00")
x.lines <- as.chron(seq.dates(startdate, enddate, by="years"))
x.limits <- c(as.chron(startdate), as.chron(enddate))

# year labels on x axis (centered between grid lines)
x.at <- as.chron(seq.dates("7/1/1992", "7/1/2004", by="years"))
x.labels <- format(as.Date(dates(x.at)), "%Y")

# dummy data
x <- x.at[1:2]
y <- c(105, 105)
id <- c(1,2)

print(xyplot(y ~ x | id,
   panel = function(x, y, subscripts, ...) {
     panel.abline(v = x.lines, col = "lightgray", lty = 1, lwd= 1.0)
     # function to plot data would go here
   },  # end of panel
   as.table=T, layout=c(1,2), main="",
   xlim=x.limits, 
   scales = list(x = list(alternating = T, at = x.at, labels = x.labels,
tck=0)),
   strip = F
 ) # end xyplot()
) # end print()

Thanks for any help,

Scott Waichler
Pacific Northwest National Laboratory
scott.waichler at pnl.gov




More information about the R-help mailing list