我想(得到建议)创建具有不同外观的箱线图并为其添加标签。预期(不完整)输出将如下所示(每个框都有四分位标签)和样本大小。
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")
最佳答案
这应该让你开始。关键是要知道如果保存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)
}
但是,我要指出,无论是谁建议您:
不应该向任何人提供有关制作图表的建议。曾经。他们成功地使您的箱线图变得更糟。
关于r - 更改箱线图的布局并为其添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13977561/