Skip to content

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

Closed
@ldecicco-USGS

Description

@ldecicco-USGS

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorscales 🐍

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions