Skip to content

Case of poor error message in PR #3659 #3945

Closed
@clauswilke

Description

@clauswilke

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    messagesrequests for improvements to error, warning, or feedback messages

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions