Im trying to crop a pacific centred world map using the naturalearth maps data as an sf object. The map was created following this answer and the following code:
worldMap <- ne_countries(scale = "medium", returnclass = "sf") %>%
st_make_valid()
target_crs <- st_crs("+proj=eqc +x_0=0 +y_0=0 +lat_0=0 +lon_0=133")
# define a long & slim polygon that overlaps the meridian line & set its CRS to match
# that of world
# Centered in lon 133
offset <- 180 - 133
polygon <- st_polygon(x = list(rbind(
c(-0.0001 - offset, 90),
c(0 - offset, 90),
c(0 - offset, -90),
c(-0.0001 - offset, -90),
c(-0.0001 - offset, 90)
))) %>%
st_sfc() %>%
st_set_crs(4326)
# modify world dataset to remove overlapping portions with world's polygons
world2 <- worldMap %>% st_difference(polygon)
#> Warning: attribute variables are assumed to be spatially constant throughout all
#> geometries
# Transform
world3 <- world2 %>% st_transform(crs = target_crs)
ggplot(data = world3, aes(group = admin)) +
geom_sf(fill = "grey")
I would like to crop to an area of interest covering the Indian and Pacific Oceans (like this screenshot taken from the "maps" world2 projection):
To crop, I tried the following:
world4 <- st_crop(world3, c(xmin= 30, ymin = -40, xmax = 230, ymax = 40))
However, the code above produces the incorrect crop with crazy small lat/long increments:
ggplot(data = world3, aes(group = admin)) +
geom_sf(fill = "grey")
If anyone can help me to figure out how to crop using lat and long to define the area for this pacific centred map it would be greatly apriciated. I know that there are other ways to obtain a pacific centred map but the future planned analysis for this project requires it to be an rnaturalearth map.