Skip to content

plot order in spplot with sp.layout

5 messages · Edzer Pebesma, Tom Gottfried, Paul Hiemstra +1 more

#
Dear list,

when doing the following, the grid is plotted on top of the sp.layout-item:

data(meuse.grid)
coordinates(meuse.grid) <- ~x+y
gridded(meuse.grid) <- TRUE
data(meuse.riv)
meuse.riv <- SpatialPolygons(list(Polygons(list(Polygon(meuse.riv)), 1)))
spplot(meuse.grid, sp.layout=list("sp.polygons", meuse.riv))

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

Do I misunderstand the documentation or is this a bug?

Thanks!
Tom
#
On 05/23/2011 03:13 PM, Tom Gottfried wrote:
Please try:

spplot(meuse.grid, sp.layout=list("sp.polygons", meuse.riv,
  first = FALSE))

I added this now to the spplot documentation.

  
    
#
Thanks! This works perfect!
Tom

Am 23.05.2011 15:25, schrieb Edzer Pebesma:

  
    
#
Hi,

An alternative approach is to use a custom panel function, which is even 
more flexible that the solution Edzer suggested. To add polygons and 
points to a grid map using a custom panel function:

spplot(grid_object, "layer_to_plot",
     panel = function(...) {
         panel.gridplot(...)
         sp.polygons(polygon_object)
         sp.points(point_object)
     })

see also the R wiki article on spatial data visualization [1].

cheers,
Paul

[1] 
http://rwiki.sciviews.org/doku.php?id=tips:spatial-data:spatial_data_visualization
On 05/23/2011 03:25 PM, Edzer Pebesma wrote:

  
    
#
Hello,

I find useful the layer and layer_ mechanism of latticeExtra:

p <- spplot(meuse.grid)

p + layer(sp.polygons(meuse.riv))

p + layer_(sp.polygons(meuse.riv))

Cheers,

Oscar.

-------------------
Oscar Perpi??n Lamigueiro
Dpto. Ingenier?a El?ctrica
EUITI-UPM

http://procomun.wordpress.com

-----------------------------------------