[R-sig-Geo] Differing pch symbols for categorical data in spplot

Lee Hachadoorian Lee.Hachadoorian+L at gmail.com
Mon Dec 20 22:00:59 CET 2010


I managed to get something working here, but can't take it any further. I
would like to map points on top of polygons using spplot, and control the
pch symbols and colors used by the points, which represent categorical
data.

I was able to get this partially working. An example using data included
with the sp package is:

#LOAD LIBRARY
library(sp)

#CREATE SpatialPolygonsDataFrame OF RIVERBED
data(meuse.riv)
meuse.lst = list(Polygons(list(Polygon(meuse.riv)), "meusee.riv"))
spdfMeuse = SpatialPolygonsDataFrame(
	SpatialPolygons(meuse.lst),
	data.frame(anything = 1, row.names = "meusee.riv")
)

#CREATE SpatialPoints OF SOIL SAMPLES
data(meuse)
coordinates(meuse) = c("x", "y")

#PLOT
spplot(spdfMeuse,
	sp.layout = list(
		"sp.points", 
		meuse, 
		pch = as.integer(meuse$soil)
	)
)

Since I'm casting soil (a 3-level factor) to integer, I can pass it as an
argument to pch. But this gives me very limited control over the symbols
used. I can add an integer to get, for example, pch 15, 16, & 17, but what
if I want to use pch 5, 13, & 17? Also, I can set the color with col =
"whatever", but I haven't been able to figure out how to print three
different colors that are linked to the three factors.

Any suggestions on how to accomplish this or otherwise improve this call
to spplot would be greatly appreciated.

Regards,
Lee Hachadoorian
PhD Student, Geography
Program in Earth & Environmental Sciences
CUNY Graduate Center



More information about the R-sig-Geo mailing list