shN*_*NIL 8 plot r ggplot2 lattice boxplot
我想(有建议这样做)创建具有不同外观的boxplot并为其添加标签.预期(未完成)输出将如下所示(每个框具有多种标签)和样本大小.

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")
Run Code Online (Sandbox Code Playgroud)
这应该让你开始.关键是要知道如果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)
}
Run Code Online (Sandbox Code Playgroud)
但是,我会指出,无论谁建议你:
不应该向任何人提供有关制作图表的建议.永远.他们成功地使您的箱线图变得更加糟糕.
