[R] Arrays of Trellis plots

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Mon Oct 27 19:29:19 CET 2008


> the example below does not work. (i know it's not supposed, but it makes 
it
> clear what i'm trying to achieve)
> 
> par(mfrow=c(2,1))
> xyplot(y~x2|x1,data=dataframe1,pch=20)
> xyplot(y~x2|x1,data=dataframe2,pch=20)
> 
> i know i could probably merge the two datasets and do something like
> xyplot(y~x2|x1+dataset,data=merged)

par is a base graphics command, and doesn't work with grid/lattice 
graphics.  While it is possible to merge grid and base graphics using for 
example the gridBase package, I suspect what you want is to draw two 
lattice plots on the same figure. For this, you need to read up on 
viewports, and try an example like this:

pushViewport(viewport(layout=grid.layout(2,1)))
pushViewport(viewport(layout.pos.row=1))
topplot = xyplot(Sepal.Length ~ Petal.Length | Species, data = iris)
print(topplot, newpage=FALSE)
upViewport()
pushViewport(viewport(layout.pos.row=2))
bottomplot = xyplot(Sepal.Width ~ Petal.Width | Species, data = iris)
print(bottomplot, newpage=FALSE)
popViewport(2)

See also section 5.5 in Paul Murrell's book ('R Graphics').

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}



More information about the R-help mailing list