[R] lattice, xyplot layout questions
Deepayan Sarkar
deepayan at stat.wisc.edu
Tue Oct 19 21:27:21 CEST 2004
On Tuesday 19 October 2004 11:23, Frank Samuelson wrote:
> 1. How do I get a grid in the background of my xyplots,
> like Figure 1 of
> http://www.ci.tuwien.ac.at/Conferences/DSC-2001/Proceedings/Murrell.p
>df
The traditional way is to use panel.grid. e.g.
xyplot(<...>
panel = function(x, y, ...) {
panel.grid(h=, v=)
panel.xyplot(x, y, ...)
})
With R 2.0.0, you could also do
xyplot(<...>, type = c("p", "g"))
as long as you are using the default panel function, but you won't be
able to control where the grid lines are drawn.
> 2. In my scatter xyplot I have multiple columns and rows of panels.
> I would like to have different y scales for panels in different
> rows (panels in same rows have same y scales). In such a
> scenario, only the outside axes are necessary, just like the case
> where all y scales are the same (scales$x$relation="same").
>
> Is there an easy way to do this, so no additional space or axis
> labels appear?
Not easy, but it's possible.
> I tried setting scales$y$relation="free" and
> scales$y$limits. This puts space between every column
> and a y axis on every panel, which isn't necessary.
> I nuked the unwanted axes by setting scales$y$at appropriately,
> and I tried to rid myself of the space using
> between=list(x=0,y=0), but that didn't work. Is there some other
> flag to try?
Yes, but only with 2.0.0. You basically need to change the
'layout.widths' settings value. To make things slightly inconvenient,
you will probably need to specify the limits (and tick positions) for
all the panels (if you just specify relation="free", there's no
guarantee all panels in a row will have the same limits -- unless of
course your data is such that they are). Here's a (slightly artificial)
example:
xyplot(as.numeric(variety) ~ yield | year * site, data = barley,
layout=c(6,2),
scales =
list(y =
list(relation="free", rot = 0,
limits = rep(list( c(0, 6), c( 5, 11 )),
c(6, 6)),
at = rep(list( 1:5, NULL, 6:10, NULL ),
c(1, 5, 1, 5) ))),
par.settings =
list(layout.widths =
list(axis.panel = rep(c(1, 0), c(1, 5)))))
If you leave out the 'par.settings' argument, this just has the effect
of suppressing the unwanted axis labels (by setting the corresponding
'at' to NULL), even though the space is allocated for them.
layout.widths$axis.panel controls the space. They don't have to be 0 or
1, any multiplier is allowed.
I Hope this makes sense.
Deepayan
More information about the R-help
mailing list