Tito Sanz
Tito Sanz

Reputation: 1362

Make a map with a group of subregions with geom_sf

I want to make a map only with the external borders by groups of subregions. Bellow are plotted all the subregions and I want to make a map but only with the external borders of the regions which are in region column in the spain object. I have tried with several aes like fill and group or even grouping by before plotting it but can't find a proper way:

library(rnaturalearth)
library(tidyverse)

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

spain %>% 
  ggplot() +
  geom_sf()

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

Just to clarify regions are a group of printed shapes in the map above:

spain %>% 
  ggplot(aes(fill = region)) +
  geom_sf() +
  theme(legend.position = "none") 

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

Upvotes: 2

Views: 1648

Answers (1)

astrofunkswag
astrofunkswag

Reputation: 2688

Both group_by and st_union are options:

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

Upvotes: 2

Related Questions