install.packages("sf")
install.packages("ggplot2")
install.packages("rnaturalearth")
install.packages("rnaturalearthdata")
library(sf)
library(ggplot2)
library(rnaturalearth)
library(rnaturalearthdata)
world <- ne_countries(scale = "medium", returnclass = "sf",)
proj_params <- "+proj=eck4 +lon_0=181 +datum=WGS84"
world_wrapped <- st_wrap_dateline(world, options = c("WRAPDATELINE=YES"))
world_eckert <- st_transform(world_wrapped, crs = proj_params)
p <- ggplot() +
geom_sf(data = world_eckert, fill = "lightyellow", color = "black") +
labs(title = "Eckert IV Projection World Map (Centered at 180°)") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5)) `
Help me solve the Eckert projection conversion in R language drawing – a lot of horizontal lines appear when 180 to 180 is 0 to 360, thank you
Use sf::st_break_antimeridian()
instead. All you have to do is ensure the anti-meridian value is the same as the lon_0 value in your projection string. You map title does not match the lon_0 value of your projection string, but lon_0 = 180
will work also.
library(sf)
library(ggplot2)
library(rnaturalearth)
# library(rnaturalearthdata) not needed for this reprex
world <- ne_countries(scale = "medium", returnclass = "sf",)
proj_params <- "+proj=eck4 +lon_0=181 +datum=WGS84"
world_eckert <- st_break_antimeridian(world, lon_0 = 181) |>
st_transform(proj_params)
ggplot() +
geom_sf(data = world_eckert, fill = "lightyellow", color = "black") +
labs(title = "Eckert IV Projection World Map (Centered at 180°)") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
2