r - ggplot在interplot中缩放x轴
问题描述
我想在 interplot 中缩放 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”)中的错误:无法将类型“闭包”强制转换为“字符”类型的向量
提前谢谢你!
解决方案
根据我过去的比例变换经验,您需要为变换定义一个函数,为逆定义另一个函数。您上面的代码示例似乎不符合该标准。
如果没有可用于测试的数据样本或 interplot,这就是我设置它的方式:
#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 和 twosdx 定义,看看它是如何进行的。
一旦代码正常工作,请随时从生产代码中删除打印语句。
推荐阅读
- python - 我想问一下通过python爬网的问题
- sass - Sass:函数按屏幕返回值
- c# - 如何在没有异步调用的情况下显示 Rad Busy 指示器
- javascript - React.js 使用非状态变量时出现错误作为组件正在更改要控制的文本类型的不受控制的输入
- android - 如何在android中使用布尔标志隐藏另一个活动的组件?
- jenkins-plugins - 安装时出错:没有这样的插件:cloudbees-folder
- wcf - 将 Swagger JSON 转换为 WCF 合同
- python - Flask:@app.route 中的代码在第二次调用时失败(永远运行)
- javascript - 单线程 Node.js 如何并发处理请求?
- python - 如何通过 Python Azure SDK 了解 Azure blob 对象的大小