Generate sp.layout items for use by spplot or plot these items directly in the traditional graphics system. Function layout.labels draws labels at the coordinates of the spatial object, and layout.scalebar returns a labeled scale bar.

layout.labels(obj, labels = TRUE, plot = FALSE)

layout.scalebar(obj, corner = c(0.05, 0.95), scale = 1,
                labels = c(0, scale), height = 0.05,
                pos = 3, ..., plot = FALSE)



an object inheriting from a Spatial class.


specification of the labels. For layout.labels:

  • a FALSE or NULL value omits labels (NULL is returned),

  • labels = TRUE uses row.names(obj),

  • a character or numeric index for a column of obj@data which contains suitable labels,

  • a vector of length length(obj) with labels,

  • or a list of arguments for panel.text, where the optional labels component follows the same rules as above.

For layout.scalebar, a character vector of length two giving the labels to be put above the left and right ends of the scale bar.


the location of the scale bar in the unit square, where c(0,0) refers to the bottom left corner. By default, the scale bar is placed in the top left corner (with a small buffer).


the width of the scale bar in the units of proj4string(obj). If identical(FALSE, is.projected(obj)) (i.e., obj has longlat coordinates), scale is interpreted in kilometres.


the height of the scale bar, see


a position specifier for the labels (see text). By default, the labels are plotted above the scale bar.


further arguments for panel.text (if plot = FALSE) or text (if plot = TRUE) to change the style of the labels, e.g., cex, col, and font.


logical indicating if the layout item should be plotted using the traditional graphics system. By default (FALSE), a list for subsequent use by spplot is returned.


For layout.labels, a single sp.layout item, which is a list with first element "panel.text" and subsequent elements being arguments to that function based on the labels specification.

For layout.scalebar, a list of sp.layout items comprising the polygonal scale bar and the labels.

If these layout functions are called with plot = TRUE, the item is plotted directly using traditional graphics functions and NULL is returned.


Sebastian Meyer


## districts in the Regierungsbezirk Weser-Ems (longlat coordinates)
mapWE <- measlesWeserEms@map
li1 <- layout.labels(mapWE, labels = list(font=2, labels="GEN"))
li2 <- layout.scalebar(mapWE, corner = c(0.05, 0.05), scale = 20,
                       labels = c("0", "20 km"))
spplot(mapWE, zcol = "AREA", sp.layout = c(list(li1), li2),
       col.regions = rev(heat.colors(100)), scales = list(draw = TRUE))

## districts in Bavaria (projected coordinates)
load(system.file("shapes", "districtsD.RData", package = "surveillance"))
bavaria <- districtsD[substr(row.names(districtsD), 1, 2) == "09", ]
sb <- layout.scalebar(bavaria, corner = c(0.75,0.9), scale = 50,
                      labels = c("0", "50 km"), cex = 0.8)
spplot(bavaria, zcol = "POPULATION", sp.layout = sb,
       xlab = "x [km]", ylab = "y [km]", scales = list(draw = TRUE),
       col.regions = rev(heat.colors(100)))

## these layout functions also work in the traditional graphics system
par(mar = c(0,0,0,0))
plot(bavaria, col = "lavender")
layout.scalebar(bavaria, corner = c(0.75, 0.9), scale = 50,
                labels = c("0", "50 km"), plot = TRUE)
layout.labels(bavaria, labels = list(cex = 0.8,
              labels = substr(bavaria$GEN, 1, 3)), plot = TRUE)