【问题标题】:Make a map with a group of subregions with geom_sf使用 geom_sf 制作包含一组子区域的地图
【发布时间】:2019-02-12 21:00:36
【问题描述】:

我想制作一张仅按子区域组的外部边界的地图。波纹管绘制了所有子区域,我想制作一张地图,但仅使用region 对象中region 列中的区域的外部边界。我已经尝试了几个aes,比如fillgroup,甚至在绘制它之前进行分组,但找不到合适的方法:

library(rnaturalearth)
library(tidyverse)

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

spain %>% 
  ggplot() +
  geom_sf()

reprex package (v0.2.1) 于 2019-02-12 创建

只是为了澄清区域是上面地图中的一组打印形状:

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

reprex package (v0.2.1) 于 2019-02-12 创建

【问题讨论】:

  • 可以对数据进行分组,使用st_union
  • 按照下面的建议summarise 完成了这项工作。感谢@camille 第二次的支持 :)

标签: r ggplot2 maps


【解决方案1】:

group_byst_union 都是选项:

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

【讨论】:

  • 在这种情况下使用summarise 是我永远无法想象的……但不知何故它起作用了!谢谢@astrofunkswag!
猜你喜欢
  • 1970-01-01
  • 2021-09-28
  • 2016-05-12
  • 2021-05-24
  • 1970-01-01
  • 2018-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多