[R] controling x-labels in xyplot (lattice) when x is POSIX object

Deepayan Sarkar deepayan at stat.wisc.edu
Mon Oct 20 19:58:36 CEST 2003


On Monday 20 October 2003 12:35, john.gavin at ubs.com wrote:
> Hi,
> 
> V1.8.0 seems to allow DateTimeClasses as the x argument in xyplots 
(lattice).
> For example:
> 
> x <- seq.POSIXt(strptime("2003/01/01", format = "%Y/%m/%d"),
>                 strptime("2003/10/01", format = "%Y/%m/%d"), by = "month")
> y <- rnorm(length(x))
> dat <- data.frame(x= x, y = y)
> xyplot(y ~ x, data = dat, type = "b")
> 
> However, the labelling for the x-axis is not what I want.
> (I see only one tick mark and one label ('Oct').)
> What is the recommended way to relabel the x-axis?
> Ideally, I want to see several months (3-6) labelled along the x-axis.

A final resort could always be to explicitly specify the at and labels 
components in scales.

> Previously, I used 'calculateAxisComponents' to massage the labels manually
> but that function (which I realise was internal to lattice) is no longer 
> available.

It's still there, but not exported (in the NAMESPACE sense). You will find it 
in the source, and perhaps be able to use it to calculate your own 'at' and 
'labels' externally.

The DateTime handling you see in 1.8.0 was actually present in earlier 
versions of lattice, only it didn't work when relation="same" (the default) 
because of a bug. In a (hopefully near) future version the axis labels 
handling will be restructured, and in particular will allow the user to 
specify the format (as in axis.POSIXct) explicitly in the high level xyplot 
call, which might make this slightly more flexible.

HTH,

Deepayan




More information about the R-help mailing list