ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

midpoint is not transformed in scale_color_gradient2

Open zeehio opened this issue 5 years ago • 0 comments

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

zeehio avatar Mar 22 '19 08:03 zeehio