File: match.map.Rd

package info (click to toggle)
r-cran-maps 3.4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,568 kB
  • sloc: ansic: 1,564; makefile: 59; awk: 21; sh: 13
file content (58 lines) | stat: -rw-r--r-- 1,958 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
\author{Tom Minka}
\name{match.map}
\alias{match.map}
\title{
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{
  \item{database}{
    character string naming a geographical database, or a map object.
    See the documentation for \code{\link{map}} for more details.
  }
  \item{regions}{
    a vector of names, or more generally regular expressions
    to match against the map region names.
  }
  \item{exact}{If \code{TRUE}, only exact matches with \code{regions}
    are considered.  Otherwise each element of \code{regions} is assumed
    to be a regular expression.
    Matches are always case-insensitive.}
  \item{warn}{If \code{TRUE}, a warning is printed when an element of
    \code{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 \code{regions} which matches the
  region name.  Matching is done as in \code{\link{map}}.
  More specifically, all regions \code{r} whose name matches 
  \code{regions[i]} will have index \code{i}.
  Unmatched regions will have index \code{NA}.
  Overlapping matches cause an error.

  This behavior differs from \code{\link{pmatch}} because a single entry
  in \code{regions} may match several entries in the map.
}
\seealso{\code{\link{grep}}}
\examples{
# filled map showing Republican vote in 1900
# (figure 6 in the reference)
data(state, package = "datasets")
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)
}
\references{
Richard A. Becker, and Allan R. Wilks,
"Maps in S",
\emph{AT&T Bell Laboratories Statistics Research Report, 1991.}
}
\keyword{dplot}