I know how to plot two plots when using the simple function plot:
old.par <- par(mfrow=c(1, 2))
plot(faithful, main="Faithful eruptions")
plot(large.islands, main="Islands", ylab="Area")
par(old.par)
this would return sth like:
I need to do the same for a fairly complex spplot function. What I'd like to have is a 3 x 3 square.
The function I want to plot 9 times is:
labelat = fivenum(gwr.res$SDF$Unempl)
labeltext = labelat
spplot(gwr.res$SDF, "Unempl", cuts = 4, at = c(fivenum(gwr.res$SDF$Unempl)), col.regions = Greens,
colorkey=list(width=0.3,
space="right",
tick.number=5,
labels=list(
at=labelat,
labels=labeltext )))
Any idea on how to solve this?
Thanks,
Use grid.arrange
from package gridExtra
. Doing grid.arrange(spplot(..),spplot(...),spplot(.....))
and so on will arrange them in a grid.
Here's an example using the meuse
data set that generates 9 such plots and then uses do.call
to save having to do grid.arrange(plots[[1], plots[[2]],
and so on up to 9:
> require(gridExtra)
> plots = lapply(names(meuse)[1:9], function(.x) spplot(meuse,.x))
> do.call(grid.arrange,plots)
Or even simpler:
grid.arrange(spplot(df.voro2, "my.data", xlab = "x", ylab = "y", main = "my title") ,
spplot(df.voro, "dummy", xlab = "x2", ylab = "y2", main = "my title2" ))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With