Prevent spData::world countries from wrapping around the map / cropping map area

Viewed 151

I am making a map using sf::world, where I would only like to plot Europe, Africa, Asia and Ocenia:

library(sf)
map = spData::world %>%
    dplyr::filter(!continent %in% c("South America", "North America", "Antarctica"))

ggplot() + 
    geom_sf(data=map, aes(geometry=geom))

enter image description here

As it stands, bits of Russia and Oceania are wrapping around and making a lot of empty space on the figure.

I have tried various combinations of st_crop from this answer, to crop out the whitespace doing:

st_crop(map, xmin=-30, xmax=180, ymin=-180, ymax=180)

But it seems to return a blank map with no geometries. I feel like the solution is a simple use of this function, but I can't get there.

2 Answers

You could use the approach proposed in this answer https://stackoverflow.com/a/67977330/7756889

library(sf)
library(ggplot2)

map = spData::world %>%
  dplyr::filter(!continent %in% c("South America", "North America", "Antarctica"))

# Russia only will not do; Fiji also crosses the antimeridean...
rossiya <- subset(map,  iso_a2 %in% c("RU", "FJ"))

pacified_rossiya <- st_shift_longitude(rossiya)

rest_of_world <- subset(map, !iso_a2 %in% c("RU", "FJ"))

map2 <- rbind(pacified_rossiya,
                rest_of_world) 

plot(st_geometry(map2))

enter image description here

It seems to work the best in base plot though, and crashes when applied to ggplot2.

A solution with tmap:

# packages
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(tmap)

# data
map = spData::world %>%
  dplyr::filter(!continent %in% c("South America", "North America", "Antarctica"))

# plot
tm_shape(map, bbox = c(-30, -60, 180, 90)) + 
  tm_polygons()

Created on 2021-07-02 by the reprex package (v2.0.0)

Check the help page of ?tm_shape for more details.

EDIT

As pointed out by @Jindra Lacko, the approach presented here simply applies a rectangular filter to the map without resolving the problems near the antimeridian.

Related