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

Error when using axis_logticks with pseudo_log transformation #6121

Open
bkohrn opened this issue Sep 25, 2024 · 1 comment · May be fixed by #6126
Open

Error when using axis_logticks with pseudo_log transformation #6121

bkohrn opened this issue Sep 25, 2024 · 1 comment · May be fixed by #6126
Labels
bug an unexpected problem or unintended behavior guides 📏

Comments

@bkohrn
Copy link

bkohrn commented Sep 25, 2024

I just updated to the latest versions of R and tidyverse (R 4.4.1, ggplot2 3.5.1), and decided to test out the new axis_logticks with a pseudo_log plot that I find myself doing fairly frequently. However, when I tried to run it, I ended up with an error message:

Error in seq.default(start, end, by = 1) : wrong sign in 'by' argument

Minimal example:

tibble("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),
    guide = "axis_logticks"
  ) 
@teunbrand
Copy link
Collaborator

Thanks for the report!
This situation should be handled more gracefully by ggplot and thus requires a fix.
Essentially, because the limits include 0, the axis assumed 0.1 is the smallest number to label via the negative.small argument.
However this is still bigger than your largest number, so it gets the order wrong.
In the meantime, you can set the negative.small argument to a smaller number, for which I recommend a number smaller than your smallest non-zero data.

library(ggplot2)

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 = scales::pseudo_log_trans(sigma = 1e-7, base = 10),
    guide = guide_axis_logticks(negative.small = 1e-7)
  ) 

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

@teunbrand teunbrand added bug an unexpected problem or unintended behavior guides 📏 labels Sep 25, 2024
@teunbrand teunbrand linked a pull request Sep 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior guides 📏
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants