我想使用“log2/(log2-1)”而不是“log2”
sp <- ggplot(cars, aes(x = speed, y = dist)) + geom_point()
sp
sp + scale_x_continuous(trans='log2') +
scale_y_continuous(trans='log2')
当我尝试时,我得到:
object 'log2/(log2-1)_trans' of mode 'function' was not found
谢谢。
最佳答案
您必须先定义函数及其反函数以进行标记,然后使用 scales 包中的 trans_new
函数:
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))
关于r - 如何使用函数通过ggplot2转换轴值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60901624/