Plot methods for spatial data with attributes

Lattice (trellis) plot methods for spatial data with attributes

spplot(obj, ...)
spplot.grid(obj, zcol = names(obj), ..., names.attr, 
	scales = list(draw = FALSE), xlab = NULL, ylab = NULL, aspect = mapasp(obj,xlim,ylim), 
	panel = panel.gridplot, sp.layout = NULL, formula, xlim = bbox(obj)[1, ], 
	ylim = bbox(obj)[2, ], checkEmptyRC = TRUE)
spplot.polygons(obj, zcol = names(obj), ..., names.attr, 
	scales = list(draw = FALSE), xlab = NULL, ylab = NULL, aspect = mapasp(obj,xlim,ylim), 
	panel = panel.polygonsplot, sp.layout = NULL, formula, xlim = bbox(obj)[1, ], 
	ylim = bbox(obj)[2, ])
spplot.points(obj, zcol = names(obj), ..., names.attr, 
	scales = list(draw = FALSE), xlab = NULL, ylab = NULL, aspect = mapasp(obj,xlim,ylim), 
	panel = panel.pointsplot, sp.layout = NULL, identify = FALSE, formula, 
	xlim = bbexpand(bbox(obj)[1, ], 0.04), ylim = bbexpand(bbox(obj)[2, ], 0.04))
mapLegendGrob(obj, widths = unit(1, "cm"), heights = unit(1, "cm"),
	fill = "black", just = "right")
sp.theme(set = FALSE, regions = list(col = bpy.colors(100)), ...)
layout.north.arrow(type = 1)
layout.scale.bar(height = 0.05)
spplot.locator(n = 512, type = "n", ...)
object of class extending Spatial-class
character; attribute name(s) or column number(s) in attribute table
names to use in panel, if different from zcol names
scales argument to be passed to Lattice plots; use list(draw = TRUE) to draw axes scales; see xyplot for full options
other arguments passed to levelplot (grids, polygons) or xyplot (points)
label for x-axis
label for y-axis
aspect ratio for spatial axes; defaults to "iso" (one unit on the x-axis equals one unit on the y-axis) but may be set to more suitable values if the data are e.g. if coordinates are latitude/longitude
depending on the class of obj, panel.polygonsplot (for polygons or lines), panel.gridplot (grids) or panel.pointsplot (p
NULL or list; see notes below
if not FALSE, identify plotted objects (currently only working for points plots). Labels for identification are the row.names of the attribute table row.names(as.data.frame(obj)). If TRUE, identify on panel (1,1); for identifying
optional; may be useful to plot a transformed value. Defaults to z~x+y for single and z~x+y|name for multiple attributes; use e.g. exp(x)~x+y|name to plot the exponent of the z-variable
numeric; x-axis limits
numeric; y-axis limits
width of grob
heights of grob
fill color of grob
grob placement justification
logical; if TRUE, trellis.par.set is called, else a list is returned that can be passed to trellis.par.set()
color ramp for the theme
height of scale bar; width is 1.0
see locator
see locator
logical; if TRUE, a check is done to see if empty rows or columns are present, and need to be taken care of. Setting to FALSE may improve speed.

  • spplot returns a lattice plot of class "trellis", if you fail to "see" it, explicitly call print(spplot(...)). If identify is TRUE, the plot is plotted and the return value is a vector with row names of the selected points.

    spplot.locator returns a matrix with identified point locations; use trellis.focus first to focus on a given panel.


Missing values in the attributes are (currently) not allowed.

spplot.grid, spplot.polygons and spplot.points are S4 methods for spplot; see spplot-methods.

Useful arguments that can be passed as ... are: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

for useful values see the appropriate documentation of xyplot and levelplot.

If obj is of SpatialPointsDataFrame, the following options are useful to pass: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

layout.north.arrow and layout.scale.bar can be used to set a north arrow or scale bar.

The sp.layout argument is either a single layout item, or a list with a layout items. A layout item is a list with its first argument the name of the layout function to be called: sp.points for SpatialPoints, sp.polygons for SpatialPolygons object, sp.lines for a SpatialLines object, and sp.text for text to place. The second argument contains the object (or text) to be plotted; remaining arguments are passed to the corresponding panel.* functions.

A special layout list item is which (integer), to control to which panel a layout item should be added. If which is present in the main, top-level list it applies for all layout items; in sub-lists with layout items it denotes the (set of) panels in which the layout item should be drawn. Without a which item, layout items are drawn in each panel.

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.

sp.theme returns a lattice theme; use trellis.par.set(sp.theme()) after a device is opened or changed to make this work. Currently, this only sets the colors to bpy.colors.



  • spplot
  • spplot.grid
  • spplot.locator
  • spplot.polygons
  • spplot.points
  • layout.north.arrow
  • layout.scale.bar
  • mapLegendGrob
  • sp.theme
  • spplot-methods
  • spplot,SpatialPixelsDataFrame-method
  • spplot,SpatialGridDataFrame-method
  • spplot,SpatialPolygonsDataFrame-method
  • spplot,SpatialLinesDataFrame-method
  • spplot,SpatialPointsDataFrame-method
trellis.par.set(sp.theme()) # sets bpy.colors() ramp
coordinates(meuse) <- ~x+y
l2 = list("SpatialPolygonsRescale", layout.north.arrow(), offset = c(181300,329800), 
	scale = 400)
l3 = list("SpatialPolygonsRescale", layout.scale.bar(), offset = c(180500,329800), 
	scale = 500, fill=c("transparent","black"))
l4 = list("sp.text", c(180500,329900), "0")
l5 = list("sp.text", c(181000,329900), "500 m")

spplot(meuse, c("ffreq"), sp.layout=list(l2,l3,l4,l5),col.regions="black",pch=c(1,2,3),
spplot(meuse, c("zinc", "lead"), sp.layout=list(l2,l3,l4,l5, which = 2),

if (require(RColorBrewer)) {
	spplot(meuse, c("ffreq"), sp.layout=list(l2,l3,l4,l5),
		col.regions=brewer.pal(3, "Set1"))
Documentation reproduced from package sp, version 0.9-17, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.