R 如何使用函数使用ggplot2变换轴值?
我想使用“log2/(log2-1)”而不是“log2”R 如何使用函数使用ggplot2变换轴值?,r,function,ggplot2,arithmetic-expressions,R,Function,Ggplot2,Arithmetic Expressions,我想使用“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') 谢谢。您必须先定义函数,然后使用scales软件包中的trans\u new函数定义标签的逆函数: log2_1 <- function(x) log2
sp <- ggplot(cars, aes(x = speed, y = dist)) + geom_point()
sp
sp + scale_x_continuous(trans='log2') +
scale_y_continuous(trans='log2')
谢谢。您必须先定义函数,然后使用scales软件包中的
trans\u 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))
log2\u 1这对我很有用。正在尝试重新启动R或重新运行库(ggplot2)
,对我无效。你能展示你的结果吗?
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))