我想在交互图中缩放x轴。但是,我得到了以下错误:
require(scales)
Reverse_TwoSD_Standardization_trans = function() trans_new("Reverse_TwoSD_Standardization", function(Tran) {Tran*2*sd(AAA)+mean(BBB)}, function() 1)
interplot(m=Model1, var1 = 'A', var2 = 'B') +
xlab('AA') +
ylab('BB') +
theme_few() + scale_x_continuous(trans = Reverse_TwoSD_Standardization_trans)paste0(x,"_trans")中的错误:不能强迫类型‘闭包’为‘字符’类型的向量
谢谢你的进阶!
发布于 2019-09-27 17:13:45
根据我过去对比例转换的经验,您需要为您的转换定义一个函数,为您的逆定义另一个函数。上面的代码示例似乎不符合这一标准。
如果没有一个可供测试的数据或插画样本,我会这样设置它:
#define the mean() and 2*sd() globally in order to perform the transformation and the inverse
meanx<-mean(#your x axis variable goes here)
twosdx<-2*sd(#your x axis variable goes here)
#custom transformn
custom<-function(x){
(x-meanx)/twosdx
}
#inverse custom function
icustom<-function(x){
y<-x*twosdx+meanx
print(paste("icustom",x, y)) #debug statement
return(y)
}
interplot(m=Model1, var1 = 'A', var2 = 'B') +
xlab('AA') +
ylab('BB') +
theme_few() + scale_x_continuous(trans=scales::trans_new("custom", custom, icustom))将x变量替换为xmean定义,看看它是如何进行的。
一旦代码正常工作,可以自由地从生产代码中删除print语句。
https://stackoverflow.com/questions/58137599
复制相似问题