[R] restricting lattice pages to one
Deepayan Sarkar
deepayan.sarkar at gmail.com
Fri Sep 26 00:15:10 CEST 2008
On Thu, Sep 25, 2008 at 7:33 AM, John Fox <jfox at mcmaster.ca> wrote:
> Dear list members,
>
> I'd like to be able to restrict the number of pages in a lattice display to
> one without having to specify explicity the number of rows and columns in
> the display -- that is, having forced one page, I'd like the number of rows
> and columns to be determined automatically.
>
> For example, the following code produces two pages of output, with the
> second replacing the first on the trellis device:
>
> A <- factor(rep(c("a1", "a2"), c(20, 20)))
> B <- factor(rep(rep(c("b1", "b2"), c(10, 10)), 2))
> C <- factor(rep(rep(c("c1", "c2"), c(5, 5)), 4))
> X <- rnorm(40)
> Y <- X + 0.2*rnorm(40)
> trellis.device()
> xyplot(Y ~ X | A + B + C)
>
> I can get what I want via
>
> xyplot(Y ~ X | A + B + C, layout=c(4, 2, 1))
>
> but in the application I have in mind, I'd like to avoid having to compute
> the rows and columns.
A general (but two-step) solution is
p = xyplot(Y ~ X | A + B + C)
update(p, layout = c(0, prod(dim(p))))
Another solution that is effectively the same (with different strip
annotation) is to use an interaction as the single conditioning
variable.
xyplot(Y ~ X | A:B:C)
-Deepayan
More information about the R-help
mailing list