[R-sig-Geo] Differing pch symbols for categorical data in spplot
Dylan Beaudette
dylan.beaudette at gmail.com
Mon Dec 20 22:09:43 CET 2010
On Mon, Dec 20, 2010 at 1:00 PM, Lee Hachadoorian
<Lee.Hachadoorian+L at gmail.com> wrote:
> 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.
>
Hi Lee,
One of the tricks required to get lattice graphics to do what you want
is to master either the par.settings argument to lattice plotting
functions (e.g. spplot) or the trellis.par.set function.
Be sure to call trellis.par.set() each time you start a new device.
Here is a link to a document on this very topic (note shameless self-promotion):
http://casoilresource.lawr.ucdavis.edu/drupal/node/962
Cheers,
Dylan
More information about the R-sig-Geo
mailing list