使用ggplot2将抖动应用于boxplot中的异常值数据 [英] apply jittering to outliers data in a boxplot with ggplot2
本文介绍了使用ggplot2将抖动应用于boxplot中的异常值数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您是否知道如何仅将抖动应用于箱线图的异常数据?这是代码:
do you have any idea of how to apply jittering just to the outliers data of a boxplot? This is the code:
ggplot(data = a, aes(x = "", y = a$V8)) +
geom_boxplot(outlier.size = 0.5)+
geom_point(data=a, aes(x="", y=a$V8[54]), colour="red", size=3) +
theme_bw()+
coord_flip()
谢谢!!
推荐答案
在数据集中添加了一个向量,以指示哪些点是异常点,哪些不是异常点。然后,将 geom_boxplot
设置为不绘制任何离群值,并使用 geom_point
显式绘制离群值。
Added a vector to your data set to indicate which points are and are not outliers. Then, Set the geom_boxplot
to not plot any outliers and use a geom_point
to plot the outliers explicity.
我将使用 ggplot2
中的钻石
数据集进行说明。 / p>
I will use the diamonds
data set from ggplot2
to illustrate.
library(ggplot2)
library(dplyr)
diamonds2 <-
diamonds %>%
group_by(cut) %>%
mutate(outlier = price > median(price) + IQR(price) * 1.5) %>%
ungroup
ggplot(diamonds2) +
aes(x = cut, y = price) +
geom_boxplot(outlier.shape = NA) + # NO OUTLIERS
geom_point(data = function(x) dplyr::filter_(x, ~ outlier), position = 'jitter') # Outliers
这篇关于使用ggplot2将抖动应用于boxplot中的异常值数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文