[R-sig-Geo] Overlay Spatial Points Data Frame over Raster Layer

Bea GD aguitatierra at hotmail.com
Thu Apr 17 13:09:10 CEST 2014


Dear list,

I'd like to overlay points and associated attributes on a raster layer. 
Therefore, I'd like the points to give me more information than just its 
coordinates.

I show you with an example:

# 1.  Load data
# Points data: 'meuse.points' "SpatialPointsDataFrame"
data(meuse)
coordinates(meuse) <- ~x+y
meuse.points <- meuse

# Raster data: 'meuse.raster'
data(meuse.grid)
gridded(meuse.grid) <- ~x+y # SpatialPixelDataFrame
# Coerce to raster
meuse.raster <- raster(meuse.grid) # "RasterLayer"


# 2. Plotting
# Plot points with attributes
spplot(meuse.points, "soil", key.space = "bottom")

# Plot(meuse.raster)
plot(meuse.raster)

# Somehow, I'd like is to join these two plots above. I've been looking 
for information and trying different possibilities but none seems to 
work. Does anyone know what I'm not doing correctly?
# Plot points overlaying raster. It doesn't work!
plot(meuse.raster,
      addfun=(spplot(meuse.points, "soil", key.space="bottom")), add=T)

Many thanks in advance!



More information about the R-sig-Geo mailing list