Tito Sanz
Tito Sanz

Reputation: 1362

How to obtain maps with regions and subregions

My problem: I want to obtain a map from a given country with subregions in r.

So far: For example map package provides counties map which database produces a map of the counties of the United States mainland generated from US Department of the Census data. Or for example italy map which provides subregions, such as in a pair of lines of code is possible to plot it:

it <- ggplot2::map_data("italy")

library(ggplot2)

ggplot(it, aes(long, lat, group = group)) +
  geom_polygon() +
  coord_fixed()

I would like to obtain same maps for another countries but unfortunately I think that maps package only provides this information for USA, Italy and France. Is there a package which provides such information?

Upvotes: 3

Views: 3649

Answers (1)

Tito Sanz
Tito Sanz

Reputation: 1362

Based on the @alistaire's comment:

library("rnaturalearth")
library("ggplot2")
spain <- ne_states(country = "spain", returnclass = "sf")

ggplot(data = spain) +
  geom_sf()

Created on 2019-01-20 by the reprex package (v0.2.1)

As proposed here regions can be obtained just using group_by and summarise:

spain %>% 
  group_by(region) %>% 
  summarise() %>% 
  ggplot() +
  geom_sf() +
  theme(legend.position = 'none')

Created on 2019-02-12 by the reprex package (v0.2.1)

Upvotes: 5

Related Questions