如何在一个图像中的几个箱形图中的值在Boxplot中的R中 [英] How to put Values on Boxplot in R for several boxplot in one image

查看:689
本文介绍了如何在一个图像中的几个箱形图中的值在Boxplot中的R中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在R中绘制Delta〜Project.Types。我有10个项目类型。我知道如何做盒子:
boxplot(Delta〜Project.Types)。但是,如何将fivenum(最小,最大,第一,第二和第三分位数)放在每个箱线图上?我怎么能做到这一点,图像的每个箱线图都会显示五个数字?

I want to plot Delta~Project.Types in R. I have 10 Project Types. I know how to do the boxplot : boxplot(Delta~Project.Types). However, how can I put the fivenum (min, max, 1st, 2nd, and 3rd quantile) on each boxplot? How can I do for that every boxplot of the image will have its five number shown? That would be easier to compare the boxplots when the values are shown

谢谢!

推荐答案

您也可以使用 fivenum

five <- by(InsectSprays$count, InsectSprays$spray, fivenum)
do.call(cbind, five)
#         A    B   C    D   E  F
# [1,]  7.0  7.0 0.0  2.0 1.0  9
# [2,] 11.0 12.0 1.0  3.5 2.5 12
# [3,] 14.0 16.5 1.5  5.0 3.0 15
# [4,] 18.5 18.0 3.0  5.0 5.0 23
# [5,] 23.0 21.0 7.0 12.0 6.0 26

或者,这些统计信息是返回值之一 boxplot (注意,您需要使用 range = 0 获取最小值和最大值,因为有一些值是外围):

Alternatively, these stats are one of the return values of boxplot (note that you need to use range = 0 to get the min and max since there are some values which are outlying):

bp <- boxplot(count ~ spray, data = InsectSprays, col = "lightgray", range = 0)
bp$stats
#      [,1] [,2] [,3] [,4] [,5] [,6]
# [1,]  7.0  7.0  0.0  2.0  1.0    9
# [2,] 11.0 12.0  1.0  3.5  2.5   12
# [3,] 14.0 16.5  1.5  5.0  3.0   15
# [4,] 18.5 18.0  3.0  5.0  5.0   23
# [5,] 23.0 21.0  7.0 12.0  6.0   26

然后只需添加到每个框: / p>

Then just add to each box:

text(x = col(bp$stats) - .5, y = bp$stats, labels = bp$stats)

这篇关于如何在一个图像中的几个箱形图中的值在Boxplot中的R中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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