r-spatial / sf

Simple Features for R
https://r-spatial.github.io/sf/
Other
1.34k stars 297 forks source link

Setting lims alters the shape of geom_sf #2461

Open liuyadong opened 2 hours ago

liuyadong commented 2 hours ago

Describe the bug

Hi, I'm making maps of Russia using geom_sf, but the height/width ratio seems off. Is there a way to maintain the shape as it appears in a global context?

To Reproduce

library(sf)
#> Linking to GEOS 3.13.0, GDAL 3.9.2, PROJ 9.5.0; sf_use_s2() is TRUE
library(rnaturalearth)
library(ggplot2)
russia <- ne_countries(country = "russia", returnclass = "sf")
russia |>
  st_bbox(russia)
#>       xmin       ymin       xmax       ymax 
#> -180.00000   41.15142  180.00000   81.25040

ggplot() +
  geom_sf(data = russia) +
  coord_sf(crs = 4326, expand = F)


ggplot() +
  geom_sf(data = russia) +
  coord_sf(crs = 4326, expand = F) +
  ylim(-90, 90)

Created on 2024-10-23 with reprex v2.1.1

edzer commented 2 hours ago

Here are two things you could try:

ortho = st_crs("+proj=ortho +lon_0=90 +lat_0=60")                                                                           |  /tmp/Nvim-R-edzer/Rsource-430273:4:0: unexpected end of input                 
ggplot() +                                                                                                                  |2:   geom_sf(data = st_transform(russia, "+proj=eqc +lon_0=-90") +              
  geom_sf(data = st_transform(russia, ortho))                                                                               |3:   coord_sf(crs = 4326, expand = F)                                           
eqc = st_crs("+proj=eqc +lon_0=90")                                                                                         |  ^                                                                             
ggplot() +                                                                                                                  |> NvimR.chunk(echo=TRUE)                                                        
  geom_sf(data = st_transform(russia, eqc)) 
liuyadong commented 2 hours ago

Thanks @edzer Russia is just one example, but more generally, it seems that QGIS can preserve the shape as it appears in a global context. I’m curious if geom_sf offers a similar option without changing the projection.

edzer commented 1 hour ago

What exactly do you mean by global context? Could you share the QGIS image?