改变boxplot的布局并为其添加标签 [英] changing layout of boxplot and adding labels to it

查看:1215
本文介绍了改变boxplot的布局并为其添加标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想(有建议这么做)用不同的外观创建boxplot并为其添加标签。预期(不完整)的输出将如下所示(每个盒子都有quatile labeles)和样本大小。



  boxplot(len〜supp * dose,data = ToothGrowth,notch = TRUE,
col =(c(gold,darkgreen )),
main =牙齿增长,xlab =Suppliment and Dose,names = supp)

#一些不成功的试验
#添加名称
盒子图(len〜supp * dose,data = ToothGrowth,notch = TRUE,
col =(c(gold,darkgreen)),
main =牙齿增长,xlab = Suppliment and Dose,name = supp * dose)
#去除绘图轮廓
boxplot(len〜supp * dose,data = ToothGrowth,notch = TRUE,
col =(c gold,darkgreen)),
main =牙齿增长,xlab =Suppliment and Dose,bty =n)


解决方案

这应该让你开始。关键是要知道,如果在设置 plot = FALSE 时将 boxplot 的结果保存到对象中,关于每个对象所到达的所有信息。然后,您可以使用此信息通过 text 添加文本。

  d <  - 箱线图(LEN〜SUPP *剂量,数据= ToothGrowth,情节= FALSE)

箱线图(LEN〜SUPP *剂量,数据= ToothGrowth,缺口= TRUE,
栏=( c(gold,darkgreen)),
main =牙齿增长,xlab =Suppliment and Dose,axes = FALSE)

(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)
}

然而,我会指出,无论谁建议你:


  • 删除坐标轴

  • 使用分位数值和样本大小为每个boxplot注释不应该给任何人提供关于制作图表的建议。永远。他们已经成功地使你的boxplot变得更糟,更糟糕。


    I want to (got suggestion to do so) create boxplot with different look and added labels to it. The expected (not complete) output will look like the following (with every box has quatile labeles) and sample size.

     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")
    

    解决方案

    This should get you started. The key is to know that if you save the results of boxplot into an object while setting plot = FALSE, you get all the information for where each of the objects goes. Then you can use this information to add text via 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)
    }
    

    I would, however, point out that whoever suggested that you:

    • remove the axes
    • annotate each boxplot with the quantile values and sample sizes

    should not be giving advice to anyone about making graphs. Ever. They have successfully made your boxplot much, much worse.

    这篇关于改变boxplot的布局并为其添加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆