ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

Fix bug in `guide_axis_logticks(negative.small)`

Open teunbrand opened this issue 1 year ago • 0 comments

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

teunbrand avatar Sep 30 '24 08:09 teunbrand