I am trying to make a map using the world
dataset from spData
using a polar projection. Everything looks great, except that there are internal boundaries within Russia where it crosses the 180th meridian, and it appears that st_union()
won't dissolve polygons across that boundary, at least as I am using it. How can I dissolve the boundaries so that they don't show up on my map? I would prefer answers that use sf
.
library(sf)
library(spData)
library(dplyr)
library(ggplot2)
# polygon to crop the countries to only the northernmost ones
crop_poly <- tibble(geometry = st_sfc(st_point(c(0, 90)),
crs = 'EPSG:4326')) %>%
st_sf() %>%
st_transform(crs = 'EPSG:3413') %>%
st_buffer(dist = 3909167) %>%
smoothr::densify(n = 3) %>%
st_transform(crs = 'EPSG:4326')
# crop the world dataset
world_north <- world %>%
st_intersection(crop_poly) %>%
st_transform(crs = 'EPSG:3413') %>%
select(name_long, continent, region_un, subregion) %>%
st_union(by_feature = TRUE) # this is the suggested method for dissolving internal boundaries
# make the map
ggplot(world_north) +
geom_sf(data = crop_poly,
color = 'transparent',
fill = 'gray90',
alpha = 0.5) +
geom_sf(color = 'black', fill = 'gray80') +
geom_sf(data = crop_poly,
color = 'gray70',
fill = 'transparent',
inherit.aes = FALSE) +
# add an arrow to highlight location of undesired internal boundaries
geom_segment(x = 0, xend = -1300000,
y = 0, yend = 1300000,
arrow = arrow(),
color = 'red') +
theme_bw()
Other things I have tried
I have also tried playing around with st_wrap_dateline()
, although I'm not really sure if this is an application in which it could be useful, but I couldn't figure out a way that it would solve the issue. I attempted to use suggestions from this post to solve my problem, but I saw no difference (the internal boundaries did not get dissolved) when I tried various combinations of EPSG:32635, st_union()
, and st_simplify()
. The various permutations of code I tried are not included here to keep this post readable.