maps (version 2.0-18)

match.map: Index map regions

Description

Assigns an index to each map region, useful for map coloring.

Usage

match.map(database, regions, exact = FALSE, warn = TRUE)

Arguments

database
character string naming a geographical database, or a map object. See the documentation for map for more details.
regions
a vector of names, or more generally regular expressions to match against the map region names.
exact
If TRUE, only exact matches with regions are considered. Otherwise each element of regions is assumed to be a regular expression. Matches are always case-insensitive.
warn
If TRUE, a warning is printed when an element of regions matches nothing in the map.

Value

  • Returns an integer vector giving an index to each region in the database. The index is the index of the string in regions which matches the region name. Matching is done as in map. More specifically, all regions r whose name matches regions[i] will have index i. Unmatched regions will have index NA. Overlapping matches cause an error.

    This behavior differs from pmatch because a single entry in regions may match several entries in the map.

References

Richard A. Becker, and Allan R. Wilks, "Maps in S", AT&T Bell Laboratories Statistics Research Report, 1991. http://www.research.att.com/areas/stat/doc/93.2.ps

See Also

grep

Examples

Run this code
# filled map showing Republican vote in 1900
# (figure 6 in the reference)
data(state, package = "base")
data(votes.repub)
state.to.map <- match.map("state", state.name)
x <- votes.repub[state.to.map, "1900"]
gray.colors <- function(n) gray(rev(0:(n - 1))/n)
color <- gray.colors(100)[floor(x)]
map("state", fill = TRUE, col = color); map("state", add = TRUE)

Run the code above in your browser using DataCamp Workspace