Make a map with a group of subregions with geom_sf

廉价感情. 提交于 2019-12-13 04:40:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!