问题
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)
回答1:
Both group_by
and st_union
are options:
spain %>%
group_by(region) %>%
summarise() %>%
ggplot(aes(fill = region)) +
geom_sf() +
theme(legend.position = 'none')
来源:https://stackoverflow.com/questions/54658616/make-a-map-with-a-group-of-subregions-with-geom-sf