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

Edzer Pebesma edzer.pebesma at uni-muenster.de
Thu Apr 17 14:20:05 CEST 2014



On 04/17/2014 01:09 PM, Bea GD wrote:
> 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)

after
plot(meuse.raster)
,
points(meuse, col= meuse$soil, pch=16)

will give you coloured points on top of the raster, but not the legend.
spplot and plot use lattice and base plot, respectively, which are
incompatible. You can try to use legend() to add another legend to the
base plot created this way.


> 
> Many thanks in advance!
> 
> _______________________________________________
> 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/20140417/b022d3c5/attachment.bin>


More information about the R-sig-Geo mailing list