lattice question: independent per-row or per-column scaling?
On 1/19/2009 8:51 AM, hadley wickham wrote:
On Thu, Jan 8, 2009 at 11:25 AM, Ren? J.V. Bertin <rjvbertin at gmail.com> wrote:
Hello - and happy newyear to all of you! I've got some data that I'm plotting with bwplot, a 3x2x3 design where the observable decreases with the principle independent factor, but at different rates. I'd like to get lattice to impose not a single set of axes ranges identical for all panels, but ranges that are identical for each panel row or each column. Effects will stand out much better like that. I've looked through the documentation of the latest lattice version, but I don't see a way to achieve this with a simple argument passed to bwplot. Can it be done otherwise and if so, how?
The argument for xlim or ylim can be a list. Here is the key part of
the help page for xyplot:
xlim could also be a list, with as many components as the number of
panels (recycled if necessary), with each component as described above.
This is meaningful only when scales$x$relation is "free" or "sliced", in
which case these are treated as if they were the corresponding limit
components returned by prepanel calculations.
Here is a little example:
library(lattice)
mdf <- data.frame(X1 = rep(LETTERS[1:3], each = 100*2*3),
X2 = rep(c("J","K"), 900),
X3 = rep(LETTERS[24:26], 100*3*2),
Y = c(runif(600, min=.01,max=.32),
runif(600, min=.33,max=.65),
runif(600, min=.66,max=.99)))
bwplot(Y ~ X3 | X2*X1, data = mdf,
layout=c(2,3,1),
ylim=as.data.frame(matrix(c(.01,.32,
.01,.32,
.33,.65,
.33,.65,
.66,.99,
.66,.99), nrow=2)),
scales=list(y=list(relation="free")))
It's not lattice, but you can do this with ggplot2 - see the examples for http://had.co.nz/ggplot2/facet_grid.html Regards, Hadley
Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894