[R-sig-Geo] spplot: how to group the variables according to a factor?

Martin Ivanov martin.ivanov at env.ethz.ch
Mon May 19 09:43:52 CEST 2014


Dear R users,

I need to produce a spatial plot of having 6 panels.
The upper 3 panels will contain the winter maps of 3 variables, and the lower panel will contain the summer maps of the
same three variables. I also need the outer strips, so that the figure looks something like this:

library(stats); library(latticeExtra);
useOuterStrips(dotplot(variety ~ yield | year * site, data=barley));

In this example there are 2 colums and 3 rows, and I want a 3 columns and 2 rows spatial graph
with a similar look. Is it possible to be achieved by spplot somehow? I know it is achievable by
levelplot if one defines the seasons as a conditioning variable. The problem is that I need to
additionally plot some spatial features like topography and rivers, so I need to take advantage of the
spplot features. I already tried to do that in analogy with this example

library(sp)
demo(meuse, ask = FALSE)
xyplot(y~x|ffreq, as(meuse, "data.frame"), asp="iso",
	panel = function(x,y,...) {
		sp.polygons(meuse.riv)
		# anything else you want to do in every panel
		panel.xyplot(x,y,...)
	},
	scales = list(draw = FALSE),
	xlab = NULL, ylab = NULL
)

The problem is that in my case I use levelplot with a 4-D array (3-rd dimension the 3 variables and
4th dimension the 2 seasons), so that it can automatically recognize the conditioning variable. However,
sp.polygons issued from inside the panel function does not work correctly, because x and y are factors, and
my polygons have numeric values.


Any suggestions will be appreciated.

Best regards,

-- 
Martin Ivanov
Institut für Atmosphäre und Klima
ETH Zürich
CHN L 12.3
Universitätstrasse 16
CH-8092 Zürich, Schweiz
  
Telefon: +41 44 632 80 78
E-Mail: martin.ivanov at env.ethz.ch



More information about the R-sig-Geo mailing list