2

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)

Tito Sanz
  • 1,280
  • 1
  • 16
  • 33

1 Answers1

2

Both group_by and st_union are options:

spain %>% 
  group_by(region) %>% 
  summarise() %>% 
  ggplot(aes(fill = region)) +
  geom_sf() +
  theme(legend.position = 'none')
astrofunkswag
  • 2,608
  • 12
  • 25
  • Use `summarise` in this case is something that I would never imagine... but somehow it works! Thanks @astrofunkswag ! – Tito Sanz Feb 12 '19 at 22:03