R、rnaturalearth 和 sf:从地图中删除单个边框

R, rnaturalearth and sf: remove a single border from map

请考虑 reprex 中的地图。 我不希望这成为政治,但底线是我需要“北塞浦路斯”之间的边界
“塞浦路斯”(您在 ww_ini$name_long 中找到它们)消失了。地图中的所有其他边界都可以保留。 关于如何删除地图中的单个边框的任何想法? 非常感谢!

library(tidyverse)
library(rnaturalearth)
library(sf)
#> Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0



ww_ini <- ne_countries(scale = "medium",
                       type = 'map_units',
                       returnclass = "sf")






bb <- ne_download(type = "wgs84_bounding_box", category = "physical",
                  returnclass = "sf") 
#> OGR data source with driver: ESRI Shapefile 
#> Source: "/tmp/RtmpH6Sa4R", layer: "ne_110m_wgs84_bounding_box"
#> with 1 features
#> It has 2 fields


gpl <-   ggplot(data = ww_ini) +
        geom_sf(  col = "black", lwd = 0.3 )+

        coord_sf(xlim=c(-20,45), ylim=c(30, 73) ) +
  theme_minimal()


gpl

reprex package (v2.0.0)

于 2021-08-05 创建

我建议采取以下步骤:

  • 减少数据集的维度/我希望 ISO 代码作为主键就足够了(您可以轻松地使用它来连接其他数据项); Natural Earth 数据集有 64 列,在下一步 summarise()
  • 中有点混乱
  • 筛选出两个塞浦路斯州 - ISO 代码“CYP”和“CYN” - 并通过 dplyr::summarise()
  • 将它们合并为一个多边形
  • 过滤掉“世界其他地区”国家 - ISO 代码 not 在“CYP”和“CYN”中 - 并将它们与单个塞浦路斯多边形绑定

听起来有点复杂,通过代码可能更容易理解:

cyprus <- ww_ini %>% 
  select(sov_a3) %>% 
  filter(sov_a3 %in% c("CYP", "CYN")) %>% 
  mutate(sov_a3 = "PYC") %>%  # cyprus spelled backwards
  group_by(sov_a3) %>% 
  summarise()

map_src <- ww_ini %>% 
  select(sov_a3) %>% 
  filter(!sov_a3 %in% c("CYP", "CYN")) %>% 
  bind_rows(cyprus)


gpl <-   ggplot(data = map_src  ) +
  geom_sf(  col = "black", lwd = 0.3 )+
  
  coord_sf(xlim=c(-20,45), ylim=c(30, 73) ) +
  theme_minimal()


gpl