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

Edzer Pebesma edzer.pebesma at uni-muenster.de
Mon May 19 16:57:03 CEST 2014


spplot does not support outer strips; I would try to directly use
lattice::levelplot, and sp.polygons added to the default panel function.

To plot array data with levelplot, you need to convert them to a long
table, this can be done for instance with plyr::adply.

On 05/19/2014 09:43 AM, Martin Ivanov wrote:
> 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,
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAC227795

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20140519/1b69418e/attachment.bin>


More information about the R-sig-Geo mailing list