Learn R Programming

TeachingDemos (version 1.2)

identify.Map: Identify polygons within a plotted map from the maptools packages.

Description

This function allows you to click in a polygon in a map plotted using the maptools package and labels the polygon.

Usage

identify.Map(x, labels = as.character(Map$att.data$NAME), n = Inf, ...)

identify.polylist(...)

Arguments

x
The map object plotted using plot.Map.
labels
Vector of labels used to label the polygons.
n
Maximum number of polygons to label.
...
Additional arguments passed to identify.Map or text.

Value

  • A vector of integers corresponding to the polygons clicked on.

Details

The function identify.polylist is just a wrapper function for identify.Map which handles both types of data. The point you click on is checked against every polygon in the map, so this function may be slow on very complicated maps. Right click on the map to stop before n.

See Also

plot.Map in the maptools package, identify

Examples

Run this code
library(maptools)
plot(state.vbm)
identify(state.vbm) # now click on the map a few times.

plot(state.vbm)
identify(state.vbm, state.abb, n=5)

Run the code above in your browser using DataLab