[R] restricting lattice pages to one

John Fox jfox at mcmaster.ca
Fri Sep 26 03:02:47 CEST 2008


Dear Deepayan,

Thanks for getting back to me. In the interim, I computed the layout that I wanted in the more complicated context in which the problem arose, but I'll certainly keep this clever idea in mind. 

Regards,
 John

------------------------------
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox


> -----Original Message-----
> From: Deepayan Sarkar [mailto:deepayan.sarkar at gmail.com]
> Sent: September-25-08 6:15 PM
> To: John Fox
> Cc: r-help at r-project.org
> Subject: Re: [R] restricting lattice pages to one
> 
> 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