On 1/8/07, Benjamin Tyner <btyner at stat.purdue.edu>
wrote:> When plotting over multiple pages in lattice, I'd like to be able to
> have "same" scales within a page, but "free" scales
between pages. In
> other words, something like:
>
> z<-data.frame(x=1:100,
> y=runif(100),
> d=rep(1:2,50),
> p=rep(1:2,each=50))
>
> plot<-xyplot(y~x|d*p,
> data=z,
> scales=list(x=list(relation="free")),
> layout=c(1,2))
>
> but within a page, to have common x-axes. As long as 'x' is sorted,
I
> can get the desired effect by transforming x to a relative scale:
>
> plot<-xyplot(y~unlist(with(z,tapply(x,p,function(x)
> (x-min(x))/diff(range(x)))))|d*p,
> data=z,
> layout=c(1,2))
>
> except that I'd like the tickmark labels to be in the original units of
> 'x'. I've started looking at xscale.components.default to see
whether it
> can work on a per-page (instead of per-panel) basis, but I get the
> nagging suspicion that I'm making this harder than it needs to be. Any
> assistance greatly appreciated.
A "nice" solution is unlikely. As a general rule, the trellis object
doesn't know anything about what layout it's going to be plotted with,
and unfortunately the panel-specific scales are determined when the
object is created, not when it is plotted (I don't remember all the
reasons for this choice, but changing it would require a major
overhaul). A similar task, row-specific or column-specific "free"
scales, is difficult for the same reason.
If I need to do this, I usually have in scales
1. relation="free"
2. limits = list(lim1, lim2, ...) where lim1, lim2, etc are
packet-specific limits (they have to be supplied explicitly). You can
omit this if you can make sure your prepanel function gives you the
right things.
This will almost do what you want, but will repeat the ticks/labels
for every panel. To suppress that you can additionally have
3. at = list(TRUE, NULL, ...) etc where NULL means ticks/labels won't be
drawn.
This doesn't really help, because the space will still be wasted, so
finally,
4. add par.settings = list(layout.heights = list(axis.panel = c(1, 0, ...)))
-Deepayan