Skip to content

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!

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