从ggplot2中的stat_summary中删除异常值
我有这个代码的一部分来生产我的数据:
p <- ggplot(meltData, aes(x=variable, y=value)) +
geom_boxplot()+ geom_boxplot(outlier.colour="red", outlier.shape=1,outlier.size=2)+
stat_summary(geom="text", fun=quantile,
aes(label=sprintf("%1.1f", ..y..), color=factor(variable)),
position=position_nudge(x=0.0), size=3.5,show_guide = FALSE)+
ggtitle("Species measurements")+
ggeasy::easy_center_title()
p
我希望能够在我的框图上看到 uppper和lower Whisker编号作为最大值和最小值(而不是异常值)。例如,在第五个框图上,我们可以看到最大数字为72,但这是一个离群值,最大值应大约为56。
I have this part of code to produce boxplot with my data:
p <- ggplot(meltData, aes(x=variable, y=value)) +
geom_boxplot()+ geom_boxplot(outlier.colour="red", outlier.shape=1,outlier.size=2)+
stat_summary(geom="text", fun=quantile,
aes(label=sprintf("%1.1f", ..y..), color=factor(variable)),
position=position_nudge(x=0.0), size=3.5,show_guide = FALSE)+
ggtitle("Species measurements")+
ggeasy::easy_center_title()
p
I want to be able to see uppper and lower whisker numbers on my boxplot as maximum and minimum values (and not the outliers numbers). For example, on the 5th boxplot we can see that the max number is 72, but this is an outlier and the max should be at 56 approximately.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解您的目的,则需要创建盒子图以及显示上下晶须数量的文本,并且图中不应显示异常值。如果这是真的,那么我同意您可能要过滤每个类别的异常值的@Death Metal。
但是,由于您没有提供可再现的数据,因此以下是类似于数据的虚拟数据。
清楚地显示异常值
这是在应用框图之前过滤异常值的方法:
结果:
If I understand your purpose correctly, you want to create boxplots along with texts that show the upper and lower whisker numbers and no outliers should be shown in the plots. If that's true, then I agree with @Death Metal that you might want to filter the outliers per category.
However, because you don't provide a reproducible data, here is a dummy data similar to your data.
which clearly shows outliers
Here is on of the ways to filter the outliers before applying boxplots:
The result: