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

stat_bin() accepts functions for argument breaks #5963

Merged
merged 2 commits into from
Jun 28, 2024

Conversation

aijordan
Copy link
Contributor

This PR is a recreation of #4560 (which can no longer be reopened) and addresses the initial issue discussed in #4561

(Not addressed: rlang lambda function notation for breaks and binwidth)

The changes allow the breaks argument of stat_bin() to take functions as input. Example:

library(ggplot2)

df <- data.frame(
  x = c(rexp(1000), rexp(1000, 5)),
  study = c(rep("A", 1000), rep("B", 1000))
)

ggplot(df, aes(x)) +
  geom_histogram(
    mapping = aes(y = after_stat(density)),
    breaks = \(x) qexp(c(0, .25, .5, .75, .95, .99), 1/mean(x))
  ) +
  facet_wrap(vars(study))

Created on 2024-06-28 with reprex v2.1.0

Copy link
Collaborator

@teunbrand teunbrand left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great!
If you want, you could add a news bullet for this change.

@teunbrand
Copy link
Collaborator

Awesome, thank you for the contribution!

@teunbrand teunbrand merged commit 2610840 into tidyverse:main Jun 28, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants