Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot fails to render with specific lon_0 value in coord_sf crs string (works with lon_0=27.1, fails with lon_0=27.0) #6180

Closed
misea opened this issue Nov 11, 2024 · 3 comments

Comments

@misea
Copy link

misea commented Nov 11, 2024

I found a problem with rendering a world map with a very specific rotation (I was just trying to animate a rotating globe)
I expected any valid integer value of lon0 in my crs string of this form to work:

coord_sf(crs = "+proj=ortho +lat_0=0 +lon_0=27") 

but it fails with that specific string, while succeeding with other similar values

library(ggplot2)
library(rnaturalearth)
library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE

world <- ne_countries(scale = "medium", returnclass = "sf")


world_plot <- ggplot(data = world) +
   geom_sf(fill = "lightblue", color = "gray") +
     theme_void()

# This works
world_plot + coord_sf(crs = "+proj=ortho +lat_0=0 +lon_0=26.9") 

# So does this
world_plot + coord_sf(crs = "+proj=ortho +lat_0=0 +lon_0=27.1") 

  
# But this fails with "Error in `grid.Call.graphics"
world_plot + coord_sf(crs = "+proj=ortho +lat_0=0 +lon_0=27.0") 
#> Error in grid.Call.graphics(C_path, x$x, x$y, index, switch(x$rule, winding = 1L, : Invalid graphics path

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

@teunbrand
Copy link
Collaborator

Thanks for the report! It seems like the problem can be reproduced outside ggplot2, which tells me the source of the error comes from elsewhere.

library(ggplot2)
library(rnaturalearth)
library(sf)
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE

world <- ne_countries(scale = "medium", returnclass = "sf") |>
  st_as_sfc() |>
  st_transform(crs = st_crs("+proj=ortho +lat_0=0 +lon_0=27.0")) |>
  plot()

#> Error in polypath(p_bind(L), border = border[i], lty = lty[i], lwd = lwd[i], : Invalid graphics path

Created on 2024-11-11 with reprex v2.1.1

I'd try posting this as an issue in {sf} instead.

@misea
Copy link
Author

misea commented Nov 11, 2024

OK - now reported here: r-spatial/sf#2477

@teunbrand
Copy link
Collaborator

Alright, good. If it appears that the issue originates from ggplot2 anyway we can reopen this issue.

@teunbrand teunbrand closed this as not planned Won't fix, can't repro, duplicate, stale Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants