john.gavin@ubs.com
2003-Oct-20 17:35 UTC
[R] controling x-labels in xyplot (lattice) when x is POSIX object
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. Previously, I used 'calculateAxisComponents' to massage the labels manually but that function (which I realise was internal to lattice) is no longer available. I am on Windows XP, R 1.8.0. Regards, John. John Gavin <john.gavin at ubs.com>, Quantitative Risk Models and Statistics, UBS Investment Bank, 6th floor, 100 Liverpool St., London EC2M 2RH, UK. Phone +44 (0) 207 567 4289 Fax +44 (0) 207 568 5352 Visit our website at http://www.ubs.com This message contains confidential information and is intend...{{dropped}}
Deepayan Sarkar
2003-Oct-20 17:58 UTC
[R] controling x-labels in xyplot (lattice) when x is POSIX object
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
Reasonably Related Threads
- summary - controling x-labels in xyplot (lattice) when x is POSIX object
- lattice xyplot - aligning date labels so that they align with the grid lines in panel.grid
- defining a template for functions via do.call and substitute.
- defining a template for functions via do.call and substit ute.
- lapply with argument "X"