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

Handle stat_bin2d(breaks=(x=NA,y=Something)) #1126

Merged
merged 1 commit into from Jul 23, 2015

Conversation

@tgs
Copy link
Contributor

@tgs tgs commented Jun 14, 2015

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:

breaks <- list( x = sort(unique(movies$year)) - 0.5, y = NA )
g <- ggplot(movies) + aes(x = year, y = length)
g + stat_bin2d(breaks=breaks) + scale_y_log10()
stopifnot(is.list(breaks))
stopifnot(length(breaks) == 2)
stopifnot(all(sapply(breaks, is.numeric)))
breaks <- list(x = NA, y = NA)
Copy link
Member

@hadley hadley Jun 18, 2015

I think using list(x = NULL, y = NULL) makes the code below a bit simpler. Then you can just test is.null(breaks$x)

Copy link
Contributor Author

@tgs tgs Jun 20, 2015

Sure, sounds good.

@hadley
Copy link
Member

@hadley hadley commented Jun 18, 2015

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]]

@tgs
Copy link
Contributor Author

@tgs tgs commented Jun 20, 2015

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.

@tgs
Copy link
Contributor Author

@tgs tgs commented Jun 23, 2015

Ah, the integer/numeric thing seems to be a feature, rather than a bug, of R. OK.

@tgs
Copy link
Contributor Author

@tgs tgs commented Jun 23, 2015

I'm going to open a separate issue for the is.integer thing.

@hadley
Copy link
Member

@hadley hadley commented Jun 23, 2015

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

@tgs
Copy link
Contributor Author

@tgs tgs commented Jun 23, 2015

AH! That makes sense! Ignore #1147 then.

@tgs
Copy link
Contributor Author

@tgs tgs commented Jul 22, 2015

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?

@hadley
Copy link
Member

@hadley hadley commented Jul 22, 2015

The docs have been merged into geom_bin2d() (since they're basically the same). If you rebase/merge, I can do another round of review and then it should be good to merge.

@tgs
Copy link
Contributor Author

@tgs tgs commented Jul 22, 2015

I've merged, and moved my documentation change to geom_bin2d.Rd. Ready for you to take another look :)

@hadley
Copy link
Member

@hadley hadley commented Jul 22, 2015

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?

@tgs tgs force-pushed the stat-bin2d-half-specified-breaks branch 3 times, most recently from 20436e8 to 3fe8835 Jul 23, 2015
@tgs
Copy link
Contributor Author

@tgs tgs commented Jul 23, 2015

I rebased on master this morning, it looks like the build passes :)

@tgs
Copy link
Contributor Author

@tgs tgs commented Jul 23, 2015

Woops, let me fix the documentation once more.

@tgs tgs force-pushed the stat-bin2d-half-specified-breaks branch from 3fe8835 to 5d23038 Jul 23, 2015
@tgs
Copy link
Contributor Author

@tgs tgs commented Jul 23, 2015

OK, fixed.

hadley added a commit that referenced this issue Jul 23, 2015
Handle stat_bin2d(breaks=(x=NA,y=Something))
@hadley hadley merged commit f5676ac into tidyverse:master Jul 23, 2015
1 check passed
@hadley
Copy link
Member

@hadley hadley commented Jul 23, 2015

Thanks!

@tgs
Copy link
Contributor Author

@tgs tgs commented Jul 23, 2015

Thank you too!

@tgs tgs deleted the stat-bin2d-half-specified-breaks branch Jul 23, 2015
@lock
Copy link

@lock lock bot commented Jan 18, 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 Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants