如何忽略ggplot2箱线图中的异常值?我不是简单地希望它们消失(即outlier.size=0),而是希望它们被忽略,以便y轴缩放到显示第一/第三个百分位数。我的异常值导致“盒子”缩小到几乎成了一条线。有什么技术可以解决这个问题吗?
编辑示例如下:
y = c(.01, .02, .03, .04, .05, .06, .07, .08, .09, .5, -.6)
qplot(1, y, geom="boxplot")

发布于 2011-04-15 22:22:02
这是一个使用boxplot.stats的解决方案
# create a dummy data frame with outliers
df = data.frame(y = c(-100, rnorm(100), 100))
# create boxplot that includes outliers
p0 = ggplot(df, aes(y = y)) + geom_boxplot(aes(x = factor(1)))
# compute lower and upper whiskers
ylim1 = boxplot.stats(df$y)$stats[c(1, 5)]
# scale y limits based on ylim1
p1 = p0 + coord_cartesian(ylim = ylim1*1.05)https://stackoverflow.com/questions/5677885
复制相似问题