首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >交错图中的g-图刻度x轴

交错图中的g-图刻度x轴
EN

Stack Overflow用户
提问于 2019-09-27 15:36:44
回答 1查看 221关注 0票数 0

我想在交互图中缩放x轴。但是,我得到了以下错误:

代码语言:javascript
复制
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")中的错误:不能强迫类型‘闭包’为‘字符’类型的向量

谢谢你的进阶!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-27 17:13:45

根据我过去对比例转换的经验,您需要为您的转换定义一个函数,为您的逆定义另一个函数。上面的代码示例似乎不符合这一标准。

如果没有一个可供测试的数据或插画样本,我会这样设置它:

代码语言:javascript
复制
#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语句。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58137599

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档