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

n.breaks only supported when breaks = waiver() #5972

Open
teunbrand opened this issue Jul 3, 2024 · 1 comment · May be fixed by #5974
Open

n.breaks only supported when breaks = waiver() #5972

teunbrand opened this issue Jul 3, 2024 · 1 comment · May be fixed by #5974

Comments

@teunbrand
Copy link
Collaborator

This is a minor gripe, but in scale_*_continuous(n.breaks = 20), the n.breaks only kicks in when breaks = waiver() (the default).
The ask here is to also have n.breaks apply when giving a custom function(x, n) {...} so that one can flexibly combine breaks functions with the desired number of breaks.

Many scales::breaks_*() function factories have n as an argument in the constructor, so it isn't a direct problem for this function family.
However, it'd be swell if this would work for user-defined functions too.

As an example, I'd like the following two plots to be identical:

library(ggplot2)

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point()

p + scale_y_continuous(
    breaks = scales::breaks_extended(), # resulting function has `n` as argument
    n.breaks = 20
  )

p + scale_y_continuous(
    breaks = scales::breaks_extended(20),
  )

Created on 2024-07-03 with reprex v2.1.0

@teunbrand
Copy link
Collaborator Author

Also a weird false positive warning using a binned scale:

library(ggplot2)

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  scale_y_binned(breaks = scales::breaks_extended(20))
#> Warning in scale_y_binned(breaks = scales::breaks_extended(20)): Ignoring `n.breaks`. Use a breaks function that supports setting number of
#> breaks.

Created on 2024-07-03 with reprex v2.1.0

@teunbrand teunbrand linked a pull request Jul 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant