【发布时间】:2020-08-25 17:22:19
【问题描述】:
我一直在尝试将函数 trans_new 与 scales 包一起使用,但是我无法让它正确显示标签
# percent to fold change
fun1 <- function(x) (x/100) + 1
# fold change to percent
inv_fun1 <- function(x) (x - 1) * 100
percent_to_fold_change_trans <- trans_new(name = "transform", transform = fun1, inverse = inv_fun1)
plot_data <- data.frame(x = 1:10,
y = inv_fun1(1:10))
# Plot raw data
p1 <- ggplot(plot_data, aes(x = x, y = y)) +
geom_point()
# This doesn't really change the plot
p2 <- ggplot(plot_data, aes(x = x, y = y)) +
geom_point() +
coord_trans(y = percent_to_fold_change_trans)
p1 和 p2 是相同的,而我希望 p2 是对角线,因为我们正在反转反转函数。如果我用另一个函数(如 fun(x) x)替换 trans_new 中的反参数,我可以看到正确的转换,但标签完全关闭。关于如何定义反参数以获得正确的标签位置的任何想法?
【问题讨论】: