[R] How to create a list of trellis objects for grid.arrange()

Agustin Lobo aloboaleu at gmail.com
Thu Oct 27 14:57:57 CEST 2016


Given
require(raster)
require(sp)
require(gridExtra)

f <- system.file("external/test.grd", package="raster")
r <- raster(f)
p1 <- spplot(r)
p2 <- spplot(r)

I would like to plot the equivalent to

grid.arrange(p1,p2,ncol=1,nrow=2)

but keeping the trellis objects p1 and p2 within one single object (as
in practice I have many objects generated within a for() loop).

The following used to work:
ps <- c(p1,p2)
grid.arrange(ps,ncol=1,nrow=2)

but does not work any more.

How should I combine p1 and p2 into one single object that would be
accepted by grid.arrange?

Thanks
-- 
Agustin Lobo
aloboaleu at gmail.com



More information about the R-help mailing list