更改Boxplot轴标签

时间:2013-10-15 23:43:48

标签: r boxplot axis-labels

我有一个数据框mdata,其中包含我在R中的BoxPlot上绘制的列variablevalue。我正在绘制Y轴上的log10(值) &安培; X轴上的变量。我想更改Y轴上的标签,使其显示原始值而不是log10(值)。

>mdata

   ID          variable value
  SJ5444_MAXGT   coding 17455
  SJ5426_MAXGT   coding 17961
  HR1383_MAXGT   coding 17579
  HR5522_MAXGT   coding 17797
 CH30041_MAXGT   coding 20099
  SJ5438_MAXGT   coding 17467

我希望Y轴范围从min(mdata $ value)到max(mdata $ value),间隔为10000.但我无法这样做。

以下是我的代码:

boxplot(log10(as.numeric(value))~variable,data=mdata,yaxt="n",border="red",main="Boxplot: Seattle Seq Annotation")

axis(side=2,labels=seq(min(mdata$value),max(mdata$value),10000),cex.axis=0.65,tck=-0.02,at=seq(min(mdata$value),max(mdata$value),by=10000))

我试图弄清楚这里有什么问题,但不是很明显。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:3)

问题似乎是您的箱图基于log10 value,而您正在绘制的轴使用原始值。有两种方法可以解决这个问题。使用log10生成轴刻度线,或者在生成箱线图进行坐标转换时使用log="y"。以下是一些示例数据的说明:

set.seed(123)
x<-sample(100,1000,T)
var<-sample(letters[1:5],1000,T) 

选择号1:

boxplot(log10(x) ~ var,yaxt="n")
axis(side=2,labels=round(10^(seq(log10(min(x)),log10(max(x)),len=5)),2),at=seq(log10(min(x)),log10(max(x)),len=5))

enter image description here

选择编号2:

boxplot(x ~ var,yaxt="n",log="y")
axis(side=2,labels=seq(min(x),max(x),len=5),at=seq(min(x),max(x),len=5))

enter image description here

通过适当地指定at参数,您可以使用任一方法以对数或线性方式间隔刻度线,例如,此命令将在使用log="y"生成的绘图上放置均匀间隔的刻度线:

 axis(side=2,labels=round(exp(seq(log(min(x)),log(max(x)),len=5)),2),at=exp(seq(log(min(x)),log(max(x)),len=5)))

答案 1 :(得分:0)

试试这个(需要多个注释,因此减少间隔):

axis(side=2,labels=seq(min(mdata$value), max(mdata$value),1000),
         at=log10(seq(min(mdata$value),max(mdata$value),by=1000)))