改变箱图的布局,添加标签给它(changing layout of boxplot and addi

2019-08-04 10:41发布

我想(有建议这样做)创建箱线图具有不同的外观,并添加标签到它。 预期(不完整),输出将类似于以下(每框有quatile labeles)和样本大小。

 boxplot(len~supp*dose, data=ToothGrowth, notch=TRUE,
  col=(c("gold","darkgreen")),
   main="Tooth Growth", xlab="Suppliment and Dose", names = supp )

  # some  unsuccessful trials 
 # to add names 
 boxplot(len~supp*dose, data=ToothGrowth, notch=TRUE,
  col=(c("gold","darkgreen")),
   main="Tooth Growth", xlab="Suppliment and Dose", names = supp*dose)
 # to remove the plot outline 
 boxplot(len~supp*dose, data=ToothGrowth, notch=TRUE,
  col=(c("gold","darkgreen")),
   main="Tooth Growth", xlab="Suppliment and Dose", bty="n")

Answer 1:

这应该让你开始。 关键是要知道,如果你保存的结果boxplot为对象而设置plot = FALSE ,你会得到每个对象的去所有的信息。 然后你可以使用这个信息通过添加文字text

d <- boxplot(len~supp*dose, data=ToothGrowth,plot = FALSE)

 boxplot(len~supp*dose, data=ToothGrowth, notch=TRUE,
  col=(c("gold","darkgreen")),
   main="Tooth Growth", xlab="Suppliment and Dose",axes = FALSE )

for (i in 1:ncol(d$stats)){
    text(i,d$stats[,i],labels = d$stats[,i],cex = 0.75,adj = c(0.5,0))
    text(i,d$stats[5,i]+1,labels = paste0("n=",d$n[i]),cex = 0.75)
    text(i-0.25,d$stats[3,i],labels = d$names[i],adj = 1,cex = 0.75)
}

我会,但是,指出谁建议你:

  • 取出轴
  • 注释每个箱线图与所述位点数值和样本大小

不应该是有关使图表任何人提供意见。 永远。 他们成功地使你的箱线图更坏。



文章来源: changing layout of boxplot and adding labels to it