[R] plot just one page of lattice plot
Felix Andrews
felix at nfrac.org
Sun Jun 24 11:38:06 CEST 2007
Great stuff, thanks. I'm copying this solution to R-help for reference.
On 6/24/07, deepayan.sarkar at gmail.com <deepayan.sarkar at gmail.com> wrote:
> On 6/23/07, Felix Andrews <felix at nfrac.org> wrote:
> > Hi Deepayan,
> >
> > I have a Lattice question: is there any way to plot just one
> > (specified) page of a multi-page display?
>
> Not in those terms exactly. However, it is possible to plot subsets of
> a trellis object, e.g.
>
> p <- xyplot(y ~ x | a)
> # dim(p) is nlevels(a)
> p[1:3]
> p[4:6]
>
> p <- xyplot(y ~ x | a + b)
> # dim(p) is c(nlevels(a), nlevels(b))
> p[1:2, 3:4]
>
> etc. See also ?packet.panel.default (and ?print.trellis), which I just
> realized can be used to do what you want:
>
> packet.panel.page <- function(n)
> {
> ## returns a function that when used as the 'packet.panel'
> ## argument in print.trellis plots page number 'n' only
> function(layout, page, ...) {
> stopifnot(layout[3] == 1)
> packet.panel.default(layout = layout,
> page = page + n - 1,
> ...)
> }
> }
>
> data(mtcars)
> HP <- equal.count(mtcars$hp, 6)
> p <-
> xyplot(mpg ~ disp | HP * factor(cyl),
> mtcars, layout = c(0, 6, 1))
>
> print(p, packet.panel = packet.panel.page(1))
> print(p, packet.panel = packet.panel.page(2))
>
> In fact, I'm going to add this as an example in ?packet.panel.default
>
> -Deepayan
>
--
Felix Andrews / 安福立
PhD candidate, The Fenner School of Environment and Society
The Australian National University (Building 48A), ACT 0200
Beijing Bag, Locked Bag 40, Kingston ACT 2604
http://www.neurofractal.org/felix/
voice:+86_1051404394 (in China)
mobile:+86_13522529265 (in China)
mobile:+61_410400963 (in Australia)
xmpp:foolish.android at gmail.com
3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8
More information about the R-help
mailing list