map_data: Create a data frame of map data

Description Usage Arguments Examples

View source: R/fortify-map.r

Description

Easily turn data from the maps package in to a data frame suitable for plotting with ggplot2.

Usage

1
map_data(map, region = ".", exact = FALSE, ...)

Arguments

map

name of map provided by the maps package. These include maps::county(), maps::france(), maps::italy(), maps::nz(), maps::state(), maps::usa(), maps::world(), maps::world2().

region

name of subregions to include. Defaults to . which includes all subregion. See documentation for maps::map() for more details.

exact

should the region be treated as a regular expression (FALSE) or as a fixed string (TRUE).

...

all other arguments passed on to maps::map()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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",  at0 = 45.5, lat1 = 29.5)

ggplot(choro, aes(long, lat)) +
  geom_polygon(aes(group = group, fill = assault / murder)) +
  coord_map("albers",  at0 = 45.5, lat1 = 29.5)
}

ggplot2 documentation built on July 5, 2018, 1:04 a.m.