When plotting a SpatVector using ggplot2, if I define a projection using coord_sf(), it adds these lines that I think come from the data wrapping around the plot extent. Best way to fix?
library(ggplot2)
library(tidyterra)
library(terra)
library(rnaturalearth)
coast <- rnaturalearth::ne_coastline(returnclass = "sv")
ggplot() +
geom_spatvector(data = coast) +
theme_minimal()
ggplot() +
geom_spatvector(data = coast) +
coord_sf(crs = "+proj=robin",) + # Robinson projection
theme_minimal()


Use the terra::normalize.longitude() function to correct this:
library(ggplot2)
library(tidyterra)
library(terra)
library(rnaturalearth)
coast <- ne_coastline(returnclass = "sv")
coast <- normalize.longitude(coast)
ggplot() +
geom_spatvector(data = coast) +
coord_sf(crs = "+proj=robin") +
theme_minimal()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With