-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Computing stats between groups #6476
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
Comments
I'd love to write the PR to add this to |
Thanks for the report! If you want to compute stats per panel or per layer, you can use the |
Kieran, as an example, I'm going to close this issue because what you request is already possible. This may not be widely known, even among people that write ggplot2 extensions, but there is no fundamental limit that you're running up against. |
@clauswilke that is true. I'm converging on the opinion that I do see that they have completely different implementations, and maybe that's for the best, but it seems non-DRY to me. @teunbrand I do see your PR on moving things to S7, and this could potentially be a use case for a class extension (stat_bin is an extension of stat_count). But I definitely don't understand ggplot2 well enough to know this for sure. |
@kieran-mace It's important to be precise with what exactly an issue is about. This issue started out as being about computing stats between groups. If you think And then I would also suggest to not mix feature requests with proposed implementation details. Whether |
In the S7 PR, I don't replace the ggproto classes that ggplot2 and its extensions are based on. I replace the most prominent S3 classes with S7 classes. If you like help with implementing an extension (besides stack overflow), the discussions in https://github.com/ggplot2-extenders/ggplot-extension-club/discussions are open |
@clauswilke thank you very much for the feedback. |
Uh oh!
There was an error while loading. Please reload this page.
In situations when we want to calculate a group stat that requires knowledge of other groups, it would be useful for
compute_group
to have access to the rest of the dataI would like to be able to create a new property,
bin_prop
, applied toStatBin
, that returns the proportion of data in that bin, that belongs to the group.In the example below, I want to analyze the number of plays, by each player in the lakers. I will use
geom_freqpoly
to show the counts, but what I really want is the proportion of plays per player within the bin.Set up data
Just counts, close to what I want, but I would love to use a
after_stat(bin_prop)
instead.Side note
I do see that something equivalent can be done with
geom_histogram + position = 'fill'
- but I do not believe this is being done by the stat layer, but maybe by the scales layer?Desired output
Here is an example of what I'd like to achieve, but by using stats instead of precomputing the
proportion_of_plays
ahed of time`Created on 2025-05-22 with reprex v2.1.1
Suggested API
I've attempted to create a PR for this, but noticed that each group is calculated independently. Is there a solution, or workaround that you propose to create a PR that enables the calculation of
bin_prop
inStatBin
that requires calculation of proportions between groups? I do see thatafter_stat(prop)
is available forgeom_bar
so I suspect this pattern has been solved for before?The text was updated successfully, but these errors were encountered: