Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

map_data

Create a data frame of map data


Description

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

Usage

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

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)
}

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

ggplot2

Create Elegant Data Visualisations Using the Grammar of Graphics

v3.3.3
MIT + file LICENSE
Authors
Hadley Wickham [aut] (<https://orcid.org/0000-0003-4757-117X>), Winston Chang [aut] (<https://orcid.org/0000-0002-1576-2126>), Lionel Henry [aut], Thomas Lin Pedersen [aut, cre] (<https://orcid.org/0000-0002-5147-4711>), Kohske Takahashi [aut], Claus Wilke [aut] (<https://orcid.org/0000-0002-7470-9261>), Kara Woo [aut] (<https://orcid.org/0000-0002-5125-4188>), Hiroaki Yutani [aut] (<https://orcid.org/0000-0002-3385-7233>), Dewey Dunnington [aut] (<https://orcid.org/0000-0002-9415-4582>), RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.