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

Fix bug in guide_axis_logticks(negative.small) #6126

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6121.

Briefly, is ensures that the limits it uses to calculate log-breaks are sorted.
Moreover, it picks a better default value for negative.small when the scale maximum is small.

Some examples based on the issue's regex; first showing that it now doesn't error and doesn't render absurd tick marks:

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

p <- data.frame(
  "Y_val" = c(0, 1e-6, 1e-5, 1e-4),
  "X_val" = c(10, 20, 30, 40)
) |>
  ggplot(aes(x = X_val, y = Y_val)) + 
  geom_point() +
  scale_y_continuous(transform = pseudo_log_trans(sigma = 1e-7, base = 10))

p + guides(y = "axis_logticks")

Second, showing the plot with a reasonable negative.small argument for this plot:

p + guides(y = guide_axis_logticks(negative.small = 1e-7))

Lastly, showing the plot with an inappropriate negative.small argument (which still doesn't throw an error).

p + guides(y = guide_axis_logticks(negative.small = 1))

Created on 2024-09-30 with reprex v2.1.1

Comment on lines +208 to +212
tens <- tens[tens >= small]
tens <- c(tens, -tens, 0)
fives <- fives[fives >= params$negative_small]
fives <- fives[fives >= small]
fives <- c(fives, -fives)
ones <- ones[ones >= params$negative_small]
ones <- ones[ones >= small]
Copy link
Member

Choose a reason for hiding this comment

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

There is something unnerving about defining a variable in one if block (small), and then using it in another, even though the blocks have the same condition.

To be clear, it is perfectly valid, but I think it is a brittle structure

@teunbrand
Copy link
Collaborator Author

Let's wait on {scales} to release a new version so we can use r-lib/scales#452 for this

@teunbrand teunbrand marked this pull request as draft October 29, 2024 09:49
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.

Error when using axis_logticks with pseudo_log transformation
2 participants