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

Limits with NA cause errors when there is no data #3560

Closed
paleolimbot opened this issue Oct 9, 2019 · 2 comments
Closed

Limits with NA cause errors when there is no data #3560

paleolimbot opened this issue Oct 9, 2019 · 2 comments

Comments

@paleolimbot
Copy link
Member

The following should create a blank plot without erroring, but does not after #3426. This should probably be fixed in the same PR as #3448.

library(ggplot2)
ggplot(data.frame(x = numeric(0)), aes(x)) + 
  geom_point() +
  scale_x_continuous(limits = c(0, NA))
#> Warning in rep(yes, length.out = len): 'x' is NULL so the result will be
#> NULL
#> Error in ans[ypos] <- rep(yes, length.out = len)[ypos]: replacement has length zero

The offending code is here (where self$limits is not NULL and self$range$range is NULL):

ggplot2/R/scale-.r

Lines 439 to 452 in 10fa001

get_limits = function(self) {
if (self$is_empty()) {
return(c(0, 1))
}
if (is.null(self$limits)) {
self$range$range
} else if (is.function(self$limits)) {
# if limits is a function, it expects to work in data space
self$trans$transform(self$limits(self$trans$inverse(self$range$range)))
} else {
ifelse(is.na(self$limits), self$range$range, self$limits)
}
},

I think that Scale$get_limits() needs another case for limits containing NA (or Scale$is_emtpy() should return TRUE for these limits). @thomasp85 any opinion on either of these solutions?

@lock
Copy link

lock bot commented May 20, 2020

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/

1 similar comment
@lock
Copy link

lock bot commented May 20, 2020

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 May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant