File: map_data.Rd

package info (click to toggle)
r-cran-ggplot2 3.5.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 9,944 kB
  • sloc: sh: 15; makefile: 5
file content (49 lines) | stat: -rw-r--r-- 1,735 bytes parent folder | download
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fortify-map.R
\name{map_data}
\alias{map_data}
\title{Create a data frame of map data}
\usage{
map_data(map, region = ".", exact = FALSE, ...)
}
\arguments{
\item{map}{name of map provided by the \pkg{maps} package. These
include \code{\link[maps:county]{maps::county()}}, \code{\link[maps:france]{maps::france()}},
\code{\link[maps:italy]{maps::italy()}}, \code{\link[maps:nz]{maps::nz()}},
\code{\link[maps:state]{maps::state()}}, \code{\link[maps:usa]{maps::usa()}},
\code{\link[maps:world]{maps::world()}}, \code{\link[maps:world2]{maps::world2()}}.}

\item{region}{name(s) of subregion(s) to include. Defaults to \code{.} which
includes all subregions. See documentation for \code{\link[maps:map]{maps::map()}}
for more details.}

\item{exact}{should the \code{region} be treated as a regular expression
(\code{FALSE}) or as a fixed string (\code{TRUE}).}

\item{...}{all other arguments passed on to \code{\link[maps:map]{maps::map()}}}
}
\description{
Easily turn data from the \pkg{maps} package into a data frame suitable
for plotting with ggplot2.
}
\examples{
if (require("maps")) {
states <- map_data("state")
arrests <- USArrests
names(arrests) <- tolower(names(arrests))
arrests$region <- tolower(rownames(USArrests))

choro <- merge(states, arrests, sort = FALSE, by = "region")
choro <- choro[order(choro$order), ]
ggplot(choro, aes(long, lat)) +
  geom_polygon(aes(group = group, fill = assault)) +
  coord_map("albers",  lat0 = 45.5, lat1 = 29.5)
}

if (require("maps")) {
ggplot(choro, aes(long, lat)) +
  geom_polygon(aes(group = group, fill = assault / murder)) +
  coord_map("albers",  lat0 = 45.5, lat1 = 29.5)
}
}
\keyword{internal}