有没有一种简单的方法可以在 R 中标记异常值?

时间:2021-03-24 19:04:18

标签: r ggplot2 boxplot

我有一个问题,我需要在底部箱线图上打印异常值的名称。 R 中的此代码输出下图。请帮忙。谢谢。

ggplot(data=Caschool, mapping=aes(x=expnstu, y=grspan)) + geom_boxplot() + stat_summary(fun=mean, geom="point", color="red", size=3) + stat_summary(fun=median, geom="point", color="blue", size=3)

Plot

1 个答案:

答案 0 :(得分:0)

您可以使用 Boxplot() 包中的 car 函数

library(car)
Boxplot(~income, data=Prestige, id.n=Inf) # identify all outliers
Boxplot(income ~ type, data=Prestige, at=c(1, 3, 2))

查看文档:{​​{3}}