Skip to content

midpoint is not transformed in scale_color_gradient2 #3198

Closed
@zeehio

Description

@zeehio

When using scale_color_gradient2 with trans = "log10", I was expecting the midpoint to be transformed as well. The documentation does not specify how midpoint behaves under transformation.

Reproducible example

Without transformation:

library(ggplot2)
df <- data.frame(x = c(1, 10, 100), y = c(1, 10, 100), color = c(1, 10, 100))
color_midpoint <- 10
ggplot(df) +
  geom_point(aes(x = x, y = y, color = color)) +
  scale_color_gradient2(midpoint = color_midpoint, low = "red", mid = "green", high = "blue")

imatge

With transformation

ggplot(df) +
  geom_point(aes(x = x, y = y, color = color)) +
  scale_color_gradient2(midpoint = log10(color_midpoint), low = "red", 
                        mid = "green", high = "blue", trans = "log10") +
  coord_trans(x = "log10", y = "log10")

imatge

I was expecting to use midpoint = color_midpoint so the trans = "log10" would apply to both the color aesthetic and the midpoint. However I had to apply manually midpoint = log10(color_midpoint).

The main advantage of letting the trans transform the midpoint is that if I change the transformation then the midpoint keeps being valid (and consistent with the aesthetic units), while now I have to manually transform the midpoint for every transformation I use.

Is is possible to change the behaviour of midpoint so it affected by trans? If not, is it possible to document this behaviour?

Thanks for your time and splendid work

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking change ☠️API change likely to affect existing codebugan 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