这意味着如果你的变换函数是base::log
那么你的反函数就是base::exp
my_new_transform <- trans_new(name = "test",
transform = base::log,
inverse = base::exp,
breaks = c(1, 10, 100))
正如文档中所述,这是明显标记中断所必需的。
然后你可以继续使用coord_trans
with ggplot2
在你的绘图上使用这个比例。
Example
library(scales)
library(ggplot2)
cube_root <- function(x) x ^ (1/3)
cube <- function(x) x ^ 3
trans_cube <- trans_new(name = "cube root",
transform = cube_root,
inverse = cube)
# dummy data
plot_data <- data.frame(x = 1:10,
y = cube(1:10))
# without applying a transform
ggplot(plot_data, aes(x = x, y = y)) +
geom_point()
# applying a transform
ggplot(plot_data, aes(x = x, y = y)) +
geom_point() +
coord_trans(y = trans_cube)