3

Instead of 'log2', I want to use 'log2/(log2-1)'

sp <- ggplot(cars, aes(x = speed, y = dist)) + geom_point()
sp
sp + scale_x_continuous(trans='log2') +
  scale_y_continuous(trans='log2')

When I try, I get:

object 'log2/(log2-1)_trans' of mode 'function' was not found

Thanks.

Krantz
  • 1,424
  • 1
  • 12
  • 31

1 Answers1

3

You have to define the function first, and its inverse for the labelling, then use the trans_new function from the scales package:

log2_1 <- function(x) log2(x)/(log2(x)-1)
antilog2_1 <- function(x) 2^(x/(x-1))

sp + scale_x_continuous(trans = trans_new("log2_1", 
                                          transform=log2_1,
                                          inverse=antilog2_1)) +
  scale_y_continuous(trans = trans_new("log2_1", 
                                       transform=log2_1,
                                       inverse=antilog2_1))

enter image description here

Edward
  • 10,360
  • 2
  • 11
  • 26