I am trying to plot only a part of the world map, limited by a square with limits lon (-30, 90) and lat (30, 82). When I try to crop the map with sf_crop, it does not return the desired square when plotting with ggplot, even though i make sure the used world map has the “normal” crs with specifying crs = 4326.
I know I could probably introduce map limits with coord_sf, but I need an alternative solution. I would really appreciate any help.
I tried the following code that produces the described problem:
lapply(c("rnaturalearthdata", "sf", "ggplot2","dplyr"), require, character.only = TRUE)
world <- ne_coastline(scale = "small", returnclass = "sf") %>%
st_transform(world, crs = 4326)
world_cropped <- st_crop(world, xmin = -30, xmax = 90, ymin = 30, ymax = 82)
ggplot() +
geom_sf(data = world, fill = NA, color = "black")
ggplot() +
geom_sf(data = world_cropped, fill = NA, color = "black")
First map, as expected
Second cropped map, did not cut a “square” as I expected, strange result
Highlighted (by hand) the map square I want to be shown approximatelly
SkiFlyer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.