Skip to content

Add warning when raster data doesn't fall on an even grid#3256

Merged
thomasp85 merged 2 commits intotidyverse:masterfrom
thomasp85:raster-error
Apr 24, 2019
Merged

Add warning when raster data doesn't fall on an even grid#3256
thomasp85 merged 2 commits intotidyverse:masterfrom
thomasp85:raster-error

Conversation

@thomasp85
Copy link
Member

Fixes #2932

This adds a warning when geom_raster() can't truthfully represent the provided data. To avoid recompilation the call to resolution() has been changed to direct calculation.

@batpigandme can you have a look at the wording of the warning?

@thomasp85 thomasp85 requested a review from clauswilke April 23, 2019 09:45
@thomasp85 thomasp85 added this to the ggplot2 3.2.0 milestone Apr 23, 2019
@clauswilke
Copy link
Member

On first glance the code looks good to me but since the visual tests fail maybe there are some unanticipated side effects? The one difference I see between resolution() and your new code is that resolution() uses unique(as.numeric(x)) where you use unique(x).

@clauswilke
Copy link
Member

And also please make sure things behave in a reasonable way when the data vector contains only a single unique value. Not sure if that's the case right now or not. At a minimum, the warning in that case seems confusing.

R/geom-raster.r Outdated
w <- resolution(data$x, FALSE)
h <- resolution(data$y, FALSE)
x_diff <- diff(sort(unique(data$x)))
if (!length(unique(x_diff)) == 1) {
Copy link
Member

@yutannihilation yutannihilation Apr 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this assumption is too strong. For example:

unique(diff(1:10 / 10))
#> [1] 0.1 0.1 0.1 0.1

Created on 2019-04-24 by the reprex package (v0.2.1)

We need a version of unique() with tolerance.

@thomasp85 thomasp85 merged commit 4e99f95 into tidyverse:master Apr 24, 2019
@lock
Copy link

lock bot commented Oct 21, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Oct 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Warning message and support for non-uniform tile sizes in geom_raster

3 participants