在plot_ly中显示离群值 [英] Show observations that are outliers in plot_ly

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

问题描述

我正在通过R中的图绘制抖动盒图.通过绘制盒图可以交互地分析四分位数和离群值. (此处为示例: https://plot.ly/r/box-plots/)

I am plotting jitter boxplots through plotly in R. Plotly boxplots allow analyzing interactively the quartiles and the values of outliers. (Examples here: https://plot.ly/r/box-plots/)

我希望看到异常值的名称,以便稍后进行分析.

I would like to see the name of observations that are outliers, so I can analyze them later.

但是,与散点箱图相比,框图似乎没有选择看待它们所属的观察结果,而散点图可以通过文本"选项看到它.

However, it seems that boxplots don't have the option of watching to which observation they belong to, in contrast to scatter boxplots, where one can see it through 'text' option.

但是,在实施其他方法之前,我想确认没有可能绘制此信息.

Before implementing other approaches, however, I would like to confirm that there is no possibility to have this information plotted.

推荐答案

如果您仍然希望使用工具提示来标记离群值,则还可以分别标识它们,并将离群值数据集传递给add_marker(),从而覆盖箱线图离群值.尝试这样的事情:

If you still want the outliers labeled by tooltips you can also identify them separately and pass the outliers dataset to add_marker(), overwriting the boxplot outliers. Try something like this:

#Set seed
set.seed(9)

#Generate random dataset
x <- data.frame(values = rnorm(100,sd=2),labels = paste("point",as.character(1:100)))

#Get outliarsdata
vals <- boxplot(x[,"values"],plot = FALSE)

#Make outliars dataset
y <- x[x[,"values"] > vals$stats[5,1] | x[,"values"] < vals$stats[1,1],]

#Make plot
plot_ly(x,y = ~values,x = 1,type = "box") %>%
  add_markers(data = y, text = y[,'labels'])

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

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