scales icon indicating copy to clipboard operation
scales copied to clipboard

Add inverse hyperbolic sine transformation

Open frederikziebell opened this issue 4 years ago • 1 comments

Sometimes it's nice to have a 'log'-transformation that also works for negative values to have points more evenly spread-out:

ihs <- function(x){log(x+sqrt(x^2+1))}
ihs_trans <- scales::trans_new(name="ihs",transform=ihs, inverse=sinh)

set.seed(1)
data <- tibble(
  x=runif(10^4),
  y=rnorm(10^4)
)

data %>% 
  ggplot(aes(x,y)) +
    geom_point(alpha=.7) +
    ggtitle("regular")

data %>% 
  ggplot(aes(x,y)) +
    geom_point(alpha=.7) +
    scale_y_continuous(trans=ihs_trans) +
    ggtitle("ihs")

image image

frederikziebell avatar Oct 07 '20 17:10 frederikziebell

Sure, do you want to do a PR?

hadley avatar Mar 16 '22 14:03 hadley

Fixed by #360

thomasp85 avatar Nov 03 '23 10:11 thomasp85