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

Improve exponential breaks #454

Merged
merged 5 commits into from
Oct 21, 2024
Merged

Conversation

teunbrand
Copy link
Contributor

This PR aims to fix #405.

Briefly, it introduces a new breaks function for the exponential transformation: breaks_exp().
It is also incorporated in transform_exp() as the breaks function.

While it is not perfect, it most definitely is an improvement over the old situation. The way I came up with this break algorithm is just by eyeballing it. I found that if the range is greater than 3, the exponential transformation began to deform the space by a lot. When the range is smaller than 3, it wasn't too bad, so we're still using breaks_extended() there. When the range is larger than 3, we're labelling 0 and the last n - 1 integers of the range.

Some examples:

devtools::load_all("~/packages/scales/")
#> ℹ Loading scales

demo_continuous(c(0, 100), transform = "exp")
#> scale_x_continuous(transform = "exp")

Small range reverts to breaks_extended():

demo_continuous(c(0, 2.5), transform = "exp")
#> scale_x_continuous(transform = "exp")

Just after the cutoff point:

demo_continuous(c(0, 3.5), transform = "exp")
#> scale_x_continuous(transform = "exp")

Even though the limits don't include 0, the expanded range does, so we still display 0 here:

demo_continuous(c(100, 104), transform = "exp")
#> scale_x_continuous(transform = "exp")

Created on 2024-10-04 with reprex v2.1.1

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

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

Thanks for this. We can always improve further if cases with bad results are reported

@thomasp85 thomasp85 merged commit 5a3ddee into r-lib:main Oct 21, 2024
12 checks passed
@teunbrand teunbrand deleted the exponential_breaks branch October 21, 2024 13:09
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.

Better breaks calculations for exponential transformations
2 participants