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

Square-root transforms happily inverse-transforms negative values #214

Closed
paleolimbot opened this issue Jun 25, 2019 · 3 comments
Closed
Labels
bug an unexpected problem or unintended behavior

Comments

@paleolimbot
Copy link

I'm not sure if this should be fixed, but it does lead to some confusing behaviour (tidyverse/ggplot2#980):

library(scales)

trans <- sqrt_trans()
trans$inverse(-2)
#> [1] 4
trans$transform(4)
#> [1] 2

trans <- sqrt_trans()
trans$inverse(-2)
#> [1] 4

# this is what I would expect to happen
trans2 <- trans_new("sqrt2", sqrt, function(x) ifelse(x < 0, NA_real_, x^2), domain = c(0, Inf))
trans2$inverse(-2)
#> [1] NA

Created on 2019-06-25 by the reprex package (v0.2.1)

@hadley hadley closed this as completed in 7fe1b7f Oct 25, 2019
@hadley
Copy link
Member

hadley commented Nov 5, 2019

Reverting the fix because it causes a failure in ggplot2

@hadley hadley reopened this Nov 5, 2019
@zeehio
Copy link
Contributor

zeehio commented Nov 19, 2019

I would expect something like sign(x) * sqrt(abs(x)) with a reverse transform like sign(x)*x^2.

Edit: I just saw Hadley had the same idea on the ggplot2 issue

Edit2: I want to add that I would find a sqrt scale that handles negative values useful for visualization purposes regardless of the linked ggplot2 issue.

@hadley hadley added the bug an unexpected problem or unintended behavior label Apr 3, 2020
@thomasp85
Copy link
Member

Changes in ggplot2 means we can now reapply the fix

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

No branches or pull requests

4 participants