Skip to content

midpoint is not transformed in scale_color_gradient2 #3198

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

Closed
zeehio opened this issue Mar 22, 2019 · 0 comments · Fixed by #5518
Closed

midpoint is not transformed in scale_color_gradient2 #3198

zeehio opened this issue Mar 22, 2019 · 0 comments · Fixed by #5518
Labels
breaking change ☠️ API change likely to affect existing code bug an unexpected problem or unintended behavior scales 🐍

Comments

@zeehio
Copy link
Contributor

zeehio commented Mar 22, 2019

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

@thomasp85 thomasp85 added breaking change ☠️ API change likely to affect existing code bug an unexpected problem or unintended behavior labels Apr 11, 2019
@thomasp85 thomasp85 added this to the ggplot2 3.3.4 milestone Mar 25, 2021
@thomasp85 thomasp85 removed this from the ggplot2 3.4.0 milestone May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change ☠️ API change likely to affect existing code bug an unexpected problem or unintended behavior scales 🐍
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants