在一个轴上应用两个转换 [英] Apply two transformations on one axis
本文介绍了在一个轴上应用两个转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现 coord_trans
,但我想申请 log10
和
reverse
到我的x轴。我尝试过应用两次转换
I have found coord_trans
, but I'd like to apply log10
and
reverse
to my x-axis. I tried applying two transformation
ggplot(table) + aes(color=Vowel, x=F1, y=F2) + geom_point() + coord_trans(x="log10", y="log10") + coord_trans(x="reverse", y="reverse")
但只有第一个被应用。所以我试着把它们连接起来。
but only the first one was applied. So I tried linking them
ggplot(table) + aes(color=Vowel, x=F2, y=F1) + geom_point() + coord_trans(x=c("log10", "reverse"), y=c("log10", "reverse"))
这给了我一个简单的错误。
Which gives me a plain error.
'c("log10_trans", "reverse_trans")' is not a function, character or symbol
如何链接它们?
推荐答案
您可以使用 trans_new
来定义新的转换。
You can define new transformations using trans_new
.
library(scales)
log10_rev_trans <- trans_new(
"log10_rev",
function(x) log10(rev(x)),
function(x) rev(10 ^ (x)),
log_breaks(10),
domain = c(1e-100, Inf)
)
p <- ggplot(mtcars, aes(wt, mpg)) +
geom_point()
p + coord_trans(y = log10_rev_trans)
这篇关于在一个轴上应用两个转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文