john.gavin at ubs.com
2006-Jun-19 17:50 UTC
[R] lattice xyplot - aligning date labels so that they align with the grid lines in panel.grid
Hi, I have a basic question about aligning date labels for the x-axis in an xyplot so that they align with the grid lines from the panel.grid argument. For example, with x <- data.frame( date = seq(as.Date("2005/01/01"), as.Date("2006/06/01"), length.out = 20), value = runif(20)) xyplot(value ~ date, data = x, panel = function(x, y, subscripts, ...) { panel.grid(h = -1, v = -1, col = "grey", lwd = 1, lty = 1) panel.xyplot(x, y, ...) }) How can I get the labels on the x-axis to align with the vertical grid lines? i.e. I have 6 vertical grid lines by default (v = -1) in this example so I would like 6 labels along the x-axis at the same points, whereas I see only 2 (2005 and 2006). As an alternative I would be happy to just specify the number of labels as long as panel.grid's vertical lines aligned with the labels.> R.version.string[1] "Version 2.3.1 (2006-06-01)" on Windows NT4. Regards, John. John Gavin <john.gavin at ubs.com>, Commodities, FIRC, UBS Investment Bank, 2nd floor, 100 Liverpool St., London EC2M 2RH, UK. Phone +44 (0) 207 567 4289 This communication is issued by UBS AG or an affiliate ("UBS...{{dropped}}
Deepayan Sarkar
2006-Jun-19 18:57 UTC
[R] lattice xyplot - aligning date labels so that they align with the grid lines in panel.grid
On 6/19/06, john.gavin at ubs.com <john.gavin at ubs.com> wrote:> Hi, > > I have a basic question about aligning date labels for the x-axis > in an xyplot so that they align with the grid lines > from the panel.grid argument. > > For example, with > > x <- data.frame( > date = seq(as.Date("2005/01/01"), as.Date("2006/06/01"), > length.out = 20), value = runif(20)) > xyplot(value ~ date, data = x, > panel = function(x, y, subscripts, ...) > { panel.grid(h = -1, v = -1, col = "grey", lwd = 1, lty = 1) > panel.xyplot(x, y, ...) > }) > > How can I get the labels on the x-axis to align > with the vertical grid lines? > i.e. I have 6 vertical grid lines by default (v = -1) > in this example so I would like 6 labels along the x-axis > at the same points, whereas I see only 2 (2005 and 2006).You will need to do it manually, e.g.: xyplot(value ~ date, data = x, panel = function(x, y, subscripts, ...) { panel.grid(h = -1, v = 0, col = "grey", lwd = 1, lty = 1) panel.abline(v = as.Date(c("2005/01/01", "2006/01/01")), col = "grey", lwd = 1, lty = 1) panel.xyplot(x, y, ...) }) For more, you can put in more locations in panel.abline, and the same locations as tick mark positions in scales$y$at.> As an alternative I would be happy to just specify the number of labels > as long as panel.grid's vertical lines aligned with the labels.Not possible currently, unlikely to be possible ever.> > R.version.string > [1] "Version 2.3.1 (2006-06-01)" > > on Windows NT4. > > Regards, > > John. > > John Gavin <john.gavin at ubs.com>, > Commodities, FIRC, > UBS Investment Bank, 2nd floor, > 100 Liverpool St., London EC2M 2RH, UK. > Phone +44 (0) 207 567 4289 > This communication is issued by UBS AG or an affiliate ("UBS...{{dropped}} > > ______________________________________________ > R-help at 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 >-- http://www.stat.wisc.edu/~deepayan/