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

Case of poor error message in PR #3659 #3945

Closed
clauswilke opened this issue Apr 12, 2020 · 1 comment
Closed

Case of poor error message in PR #3659 #3945

clauswilke opened this issue Apr 12, 2020 · 1 comment
Labels
messages requests for improvements to error, warning, or feedback messages
Milestone

Comments

@clauswilke
Copy link
Member

clauswilke commented Apr 12, 2020

This is an issue against PR #3659, which is currently on hold pending the next minor ggplot2 release. I'm filing this so I won't forget. This should probably be fixed before the PR gets merged.

In a nutshell, in some cases coord_sf() encounters numeric issues when trying to calculate plot limits and errors out. This is fine, but the error message should inform the user how to work around this problem (by setting default_crs = NULL). Also, these numeric issues probably shouldn't arise when lims_method = "geometry_bbox", but I haven't checked this yet carefully. Reprex below.

library(sf)
library(ggplot2)

grid <- st_sf(st_make_grid(what = 'polygons'))

# Robinson, works
ggplot(grid) + geom_sf() + coord_sf(crs = st_crs(54030))

# Mollweide, doesn't work, that's Ok but error message is poor
ggplot(grid) + geom_sf() + coord_sf(crs = st_crs(54009))
#> Error: Scale limits cannot be mapped onto spatial coordinates.

# Mollweide, doesn't work, but probably should
ggplot(grid) + geom_sf() +
  coord_sf(crs = st_crs(54009), lims_method = "geometry_bbox")
#> Error: Scale limits cannot be mapped onto spatial coordinates.

# Mollweide, works
ggplot(grid) + geom_sf() +
  coord_sf(crs = st_crs(54009), default_crs = NULL)

Created on 2020-04-11 by the reprex package (v0.3.0)

@clauswilke clauswilke added this to the ggplot2 3.4.0 milestone Apr 12, 2020
@thomasp85 thomasp85 added the messages requests for improvements to error, warning, or feedback messages label Apr 30, 2020
@clauswilke
Copy link
Member Author

This is now fixed in #3659.

library(sf)
#> Warning: package 'sf' was built under R version 3.6.2
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
library(ggplot2)

grid <- st_sf(st_make_grid(what = 'polygons'))

# Robinson, works
ggplot(grid) + geom_sf() + coord_sf(crs = st_crs(54030))

# Mollweide, doesn't work, error message suggests two possible fixes
ggplot(grid) + geom_sf() + coord_sf(crs = st_crs(54009))
#> Error: Scale limits cannot be mapped onto spatial coordinates in `coord_sf()`.
#> Consider setting `lims_method = "geometry_bbox"` or `default_crs = NULL`.

# Mollweide, works
ggplot(grid) + geom_sf() +
  coord_sf(crs = st_crs(54009), lims_method = "geometry_bbox")

# Mollweide, works
ggplot(grid) + geom_sf() +
  coord_sf(crs = st_crs(54009), default_crs = NULL)

Created on 2020-06-24 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
messages requests for improvements to error, warning, or feedback messages
Projects
None yet
Development

No branches or pull requests

2 participants