[R] problem with chron scales in lattice

From: Waichler, Scott R <Scott.Waichler_at_pnl.gov>
Date: Thu 02 Jun 2005 - 03:12:35 EST

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@pnl.gov



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jun 02 03:20:17 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:20 EST