[R] Display Multiple page lattice plots

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Jun 7 21:34:28 CEST 2007


On 6/7/07, rhelp.20.trevva at spamgourmet.com
<rhelp.20.trevva at spamgourmet.com> wrote:
> Gudday,
>
> I am generating a series of lattice contourplots that are conditioned on a variable (Year) that has 27 different levels. If I try and put them all on one plot, it ends up pretty messy and you can't really read anything, so instead I have set the layout to 3x3, thus generating three pages of nine plots each. The problem is that I can't display all these on screen at once, because each subsequent page overwrites the previous one. I have found in the mailing lists how to print them to separate files without any problems eg.
>
>       p<-contourplot(log10(x)~lat*long|Year,
>                   data=data.tbl,
>                   layout=c(3,3))
>       png(file="Herring Distribution%02d.png",width=800,height=800)
>       print(p)
>       dev.off()
>
> but there doesn't seem to be anything about how to output multiple pages to the screen... I suspect that I may need to use the page=... option in contourplot command, but I can't seem to make it work. Its a simple, and not particularly important problem, but it sure is bugging me!
>

You haven't told us what you want to happen exactly. Gabor's solution
will work (on Windows), and a multi-page PDF file is a similar option
that's portable. Here's another option if you want multiple windows:

xyplot(1:10 ~ 1:10 | gl(3, 1, 10), layout = c(1, 1), page =
function(n) dev.copy(x11))

you should replace x11 with the appropriate choice on your platform.
This will produce an extra copy of the last page, which you can
suppress by making use of 'n' inside your page function.

(Unfortunately page = function(n) x11() does not work, even though
that would have been more natural.)

Another option is to print your trellis object in parts; e.g.

p<-contourplot(log10(x)~lat*long|Year,
                 data=data.tbl,
                 layout=c(3,3))

x11()
p[1:9]
x11()
p[10:18]
x11()
p[19:27]

-Deepayan



More information about the R-help mailing list