答案 0 :(得分:1)
这是一个解决方案:我们使用boxplot的输出计算异常值的数量,从图中删除异常值,然后绘制比例。
# simulate data
x <- rnorm(1000)
# first boxplot to get the stats
p <- boxplot(x)
# computing the proportion of outliers
outsiders <- data.frame(text= paste0(c(length(p$out < p$stats[1])/p$n,length(p$out > p$stats[5])/p$n)*100,"%"),
y = p$stats[c(1,5)])
# real plot
boxplot(x,outline=FALSE,ylim=c(p$stats[1]-1,p$stats[5]+1))
# we add the text in two steps because we need different adj
text(x=1,labels=outsiders$text[1],y=outsiders$y[1],adj=c(0,1))
text(x=1,labels=outsiders$text[2],y=outsiders$y[2],adj=c(0,-.5))