-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Handle stat_bin2d(breaks=(x=NA,y=Something)) #1126
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
Conversation
stopifnot(is.list(breaks)) | ||
stopifnot(length(breaks) == 2) | ||
stopifnot(all(sapply(breaks, is.numeric))) | ||
breaks <- list(x = NA, y = NA) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using list(x = NULL, y = NULL)
makes the code below a bit simpler. Then you can just test is.null(breaks$x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, sounds good.
Would you consider adding a couple of unit tests? I'd start with something like: df <- data.frame(x = 1:3, y = 1:3)
p <- ggplot(df, aes(x, y)) +
stat_bin2d()
ggplot_build(p)$data[[1]] |
Sure, I'll write some more specific unit tests. Actually, just got started, and found a bug (is.integer() doesn't work when calculating the binwidth, data$x is 'numeric'). I'll try and fix that too. |
Ah, the integer/numeric thing seems to be a feature, rather than a bug, of R. OK. |
I'm going to open a separate issue for the is.integer thing. |
I think that's by design: at this point factors are integers and everything else is numeric. It's definitely weird but it's too late to change now |
AH! That makes sense! Ignore #1147 then. |
I see that man/stat_bin2d.Rd is deleted in master. Where should documentation go? Is there any chance of getting this change in the next version of ggplot2? |
The docs have been merged into |
I've merged, and moved my documentation change to geom_bin2d.Rd. Ready for you to take another look :) |
Looks good. Could you please add a bullet to NEWS (copying the existing format) and please rebase (again) now that I've fixed all the build problems? |
20436e8
to
3fe8835
Compare
I rebased on master this morning, it looks like the build passes :) |
Woops, let me fix the documentation once more. |
3fe8835
to
5d23038
Compare
OK, fixed. |
Handle stat_bin2d(breaks=(x=NA,y=Something))
Thanks! |
Thank you too! |
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/ |
With this change, you can specify one set of breaks to
stat_bin2d
without setting the other. This is particularly useful when binning by date in one dimension, and using a transformed scale in the other dimension. This way, you don't have to figure out how to reconstruct the default breaks for the transformed scale. For example: