I use am familiar with R and ArcGIS pro. I want to plot maps using WGS84 in R using ggplot.
I get equal lat Lon grids in ArcGIS pro while zooming to, say, Germany. But I am not able to get equal grids in R using ggplot2 using WGS84.
Following is what I am trying:
library("ggplot2")
library("rnaturalearth")
library("rnaturalearthdata")
library("terra")
library("sf")
world <- ne_countries(scale = "medium", returnclass = "sf")
world_projected <- st_transform(world, crs("epsg:4326"))
ggplot(data = world_projected) +
geom_sf(fill = "transparent") +
theme(
panel.grid.major = element_line(colour = alpha("black", 0.1), linewidth=1, linetype = 1)
) +
coord_sf(xlim = c(5, 16), ylim = c(46, 56), default_crs = crs("epsg:4326"))
What I get in ArcGIS Pro
What I get in R
Thanks in advance.
Pallav
It looks like you want to plot an equidistant cylindrical projection. This is straightforward, but you will need to convert your x and y range to the correct projection too:
library(ggplot2)
library(rnaturalearth)
library(sf)
world <- ne_countries(scale = "medium", returnclass = "sf")
coords <- st_sf(a = 1:2, geom = st_sfc(st_point(c(5, 46)), st_point(c(16, 56))),
crs = 4326) |>
st_transform(crs = 4087) |>
st_coordinates()
ggplot(data = st_transform(world, crs = 4087)) +
geom_sf(fill = "transparent") +
coord_sf(xlim = coords[,1], ylim = coords[,2]) +
theme(panel.grid.major = element_line(colour = alpha("black", 0.1),
linewidth = 1)
)