[R-sig-Geo] using spplot to superimpose points and polygons on SpatialGridDataFrame

reeves at nceas.ucsb.edu reeves at nceas.ucsb.edu
Mon Sep 24 01:33:31 CEST 2007



Hello:

Thanks to the excellent example at:

http://casoilresource.lawr.ucdavis.edu/drupal/node/442

I am close to my goal of creating a map diagram in R
using raster and vector data layers.

I have set up a similar diagram using as inputs a satellite image
and point shapefile:

  cPts = readShapePoints("PSCentroidPointShape")
  ProjString = proj4string(MapPolysDataFrame)
  proj4string(cPts) = CRS(ProjString)
  psImg = readGDAL("PugetSoundSub1.img")
#
# psImg is a SpatialGridDataFrame
#
  image(PsImg) # just display the raster
#
# one way to superimpose vectors over rasters
#
  ctysPS = SpatialPolygons2PolySet(ctys)
  points(cPts,add=TRUE)
  addPolys(ctysPS)
#
# now, see if spplot works as indicated in this case by overlaying
# the points over the grid.
#
  points <- list("sp.points", cPts, pch = 4, col = "black", cex=0.5)
  greys= grey(0:256 / 256)
#
  spplot(psImg,zcol="band1",col.regions=greys,main="my
Plot",sp.layout=list(points))

OK, This generates a diagram, but the points are drawn FIRST, not
second, so they are not visible on top of the image.

This conflicts the Web site example, and the spplot help file:

The order of items in sp.layout matters; objects are drawn in the order
they appear. Plot order and prevalence of sp.layout items: for points and
lines,
sp.layout items are drawn before the points (to allow for grids and
polygons);

** for grids and polygons sp.layout is drawn afterwards (so the item will
not be overdrawn by the grid and/or polygon). **

 Although a matter of taste, transparency may help when combining things.

The only difference that I can see between my attempt and the web site
example is that the example uses a SpatialPixelsDataFrame as a base layer.

Can anyone offer insight?


And a side question: Is there a way to eliminate the grey level scale on
the right side of the spplot-generated diagram?

Version of R used: R version 2.5.0 (2007-04-23) (and also version 2.5.1)

I can provide the data files if necessary.

Thanks, Rick R




More information about the R-sig-Geo mailing list