[R-sig-Geo] Trellis with spplot

Edzer Pebesma edzer.pebesma at uni-muenster.de
Wed Sep 3 16:57:09 CEST 2014


Thanks for the reproducible example:

On 09/03/2014 04:41 PM, N St wrote:
> Hello
> 
> I would like to facet a spplot with the factors of one variable (like
> a xyplot(y~x|A)). I want to use spplot because I have to add others
> polygons layers. In my reproducible example below I would like to end
> up with three plots, one for each categorie (1,2,3) in a trellis
> 
> --------------------------
> 
> library(sp); library(lattice) ; library(RColorBrewer) ; library(latticeExtra)
> data(meuse)
> coordinates(meuse) <- c("x", "y")
> cc <- coordinates(meuse)
> m.sl <- SpatialLines(list(Lines(list(Line(cc)), "line1")))
> data(meuse.riv)
> meuse.lst <- list(Polygons(list(Polygon(meuse.riv)), "meuse.riv"))
> meuse.pol <- SpatialPolygonsDataFrame(SpatialPolygons(meuse.lst),
> data.frame(1), match.ID=FALSE)
> 
> colfactor = RColorBrewer:::brewer.pal(3,"Accent")
> pts <- list("sp.points", meuse, pch = 16, col = colfactor, cex=2,  )
> meuse.layout <- list(pts)
> 
> l <- spplot(meuse, c("soil"), scales=list(draw=T), asp="iso",
> col.regions=colfactor, cex=2)
> p <- spplot(meuse.pol, fill="blue")
> l+p

meuse$soil1 = ifelse(meuse$soil == 1, 1, NA)
meuse$soil2 = ifelse(meuse$soil == 2, 2, NA)
meuse$soil3 = ifelse(meuse$soil == 3, 3, NA)
l <- spplot(meuse, c("soil1", "soil2", "soil3"))
l+p

might get you somewhere, maybe not where you want to be, but at least
each category has a panel.

> 
> -----------------------------
> It sounds really easy but I couldn't find an answer.
> 
> Best Regards
> Nebi
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
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/20140903/c1eb63ab/attachment.bin>


More information about the R-sig-Geo mailing list