在R中的箱图上标注离群值 [英] Labeling outliers on boxplot in R

查看:774
本文介绍了在R中的箱图上标注离群值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将矩阵的每一列绘制为箱线图,然后将每个箱线图中的离群值标记为它们在矩阵中所属的行名.举个例子:

I would like to plot each column of a matrix as a boxplot and then label the outliers in each boxplot as the row name they belong to in the matrix. To use an example:

vv=matrix(c(1,2,3,4,8,15,30),nrow=7,ncol=4,byrow=F)
rownames(vv)=c("one","two","three","four","five","six","seven")
boxplot(vv)

我想在每个图(在这种情况下为30)中将异常值标记为它所属的行名称,因此在这种情况下30属于行7.是否有一种简单的方法?我已经看到与此问题类似的问题,但似乎没有一个能达到我想要的方式.

I would like to label the outlier in each plot (in this case 30) as the row name it belongs to, so in this case 30 belongs to row 7. Is there an easy way to do this? I have seen similar questions to this asked but none seemed to have worked the way I want it to.

推荐答案

在给出的示例中,这有点无聊,因为它们都是同一行.但是这是代码:

In the example given it's a bit boring because they are all the same row. but here is the code:

bxpdat <- boxplot(vv)
text(bxpdat$group,                                              # the x locations 
     bxpdat$out,                                                # the y values
     rownames(vv)[which(vv == bxpdat$out, arr.ind=TRUE)[, 1]],  # the labels
     pos = 4)  

这会在boxplot的结果中选择值等于输出"列表的行名(即异常值). Boxplot调用并返回boxplot.stats中的值.看看:

This picks the rownames that have values equal to the "out" list (i.e., the outliers) in the result of boxplot. Boxplot calls and returns the values from boxplot.stats. Take a look at:

 str(bxpdat)

这篇关于在R中的箱图上标注离群值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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