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

scale_*_steps (presumably binned_scales) doesn't like 0.01 with trans="log10" #4510

Closed
ldecicco-USGS opened this issue Jun 14, 2021 · 0 comments · Fixed by #4676
Closed

scale_*_steps (presumably binned_scales) doesn't like 0.01 with trans="log10" #4510

ldecicco-USGS opened this issue Jun 14, 2021 · 0 comments · Fixed by #4676
Labels
bug an unexpected problem or unintended behavior scales 🐍

Comments

@ldecicco-USGS
Copy link

I would like to bin my colors using a log10 transformation, and it seems that if the number 0.01 is included in the data, the scaling breaks with a warning:

Warning message:
In self$trans$transform(limits) : NaNs produced

This causes the transformation to happen, but the legend doesn't show up.

Here is an example of what doesn't work:

ggplot(data = data.frame(x = 1:5, 
                         y = c(0.01, 0.43, 0.46,
                               0.05, 0.17))) +
  geom_point(aes(x = x, y = y, color = y)) +
  scale_color_steps(trans = "log10")

Here are 3 examples that do work, which makes me suspect it is a bug:

ggplot(data = data.frame(x = 1:5, 
                         y = c(0.0101, 0.43, 0.46,
                               0.05, 0.17))) +
  geom_point(aes(x = x, y = y, color = y)) +
  scale_color_steps(trans = "log10") 

ggplot(data = data.frame(x = 1:5, 
                         y = c(0.00999, 0.43, 0.46,
                               0.05, 0.17))) +
  geom_point(aes(x = x, y = y, color = y)) +
  scale_color_steps(trans = "log10")

ggplot(data = data.frame(x = 1:6, 
                         y = c(0.01, 0.43, 0.46,
                               0.05, 0.17, 0.09))) +
  geom_point(aes(x = x, y = y, color = y)) +
  scale_color_steps()

I can speculate on why this is happening, but I'm unclear if there's an easy way to eliminate this problem.

One fix is to use "log1p" instead of "log10". It took awhile for me to pinpoint the issue and discover the solution. Even if a fix for 0.01 can't be included, it would be helpful to add some language in the binned_scale (or scale_*_steps) documentation.

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 scales 🐍
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants