当x是因子R时,绘制errbar {Hmisc} x轴

时间:2014-03-26 14:03:16

标签: r plot axis-labels r-factor

我写了这段代码:

with (data = puresa, 
      expr = errbar(Chr, Purity, Purity+sd, Purity-sd, add=F, pch=1, cap=.015))

它描绘了一个这样的情节:

enter image description here

但是我的目标是在xlab中绘制Chr,而不是像上面的绘图中那样在ylab中绘制。问题是" Chr"是一个因素。因为当我将其打印为数字时,我获得了我的目标:

with (data = puresa,
      expr =  errbar(as.numeric(Chr), Purity, Purity+sd, Purity-sd, cap=.015))

enter image description here

最后一个情节的问题是我无法用Chr名称替换xlab值。

我正在尝试使用此代码,但它无效...

with (data = puresa, 
      expr =  errbar(as.numeric(Chr), Purity, Purity+sd, Purity-sd,
                     xlab=if(is.character(Chr) || is.character(Chr)) "" else (substitute(Chr))))

enter image description here

我会帮助你,非常感谢你!

1 个答案:

答案 0 :(得分:2)

好吧我刚刚做到了!

par(las=2)
plot(as.numeric(puresa$Chr), puresa$Purity, type="n", xaxt = "n", ylim=c(0,1), main="Tumor purity", xlab="Chromosome", ylab="Purity")
errbar(as.numeric(puresa$Chr), puresa$Purity, puresa$Purity+puresa$sd, puresa$Purity-puresa$sd, add=T)
axis(1, at=1:25, labels=levels(puresa$Chr), cex.axis=0.8)

enter image description here

希望它对某人有帮助。