使用geom_sf制作带有一组子区域的地图 [英] Make a map with a group of subregions with geom_sf
问题描述
我只想按子区域组制作带有外部边界的地图.贝娄已绘制了所有子区域的图,我只想绘制一个地图,但只绘制spain
对象中region
列中区域的外部边界.我已经尝试过像fill
和group
这样的几个aes
,甚至在进行绘制之前对其进行了分组,但找不到正确的方法:
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()
由 reprex程序包(v0.2.1)于2019-02-12创建
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")
由 reprex程序包(v0.2.1)于2019-02-12创建
Created on 2019-02-12 by the reprex package (v0.2.1)
推荐答案
group_by
和st_union
都是选项:
spain %>%
group_by(region) %>%
summarise() %>%
ggplot(aes(fill = region)) +
geom_sf() +
theme(legend.position = 'none')
这篇关于使用geom_sf制作带有一组子区域的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!