How can I display outliers as percentages in a boxplot?
I do not want to see the outliers displayed as dots. I would like to see the outliers displayed as number percentages in the boxplot. Below image of how I want outliers:
How can I display outliers as percentages in a boxplot?
I do not want to see the outliers displayed as dots. I would like to see the outliers displayed as number percentages in the boxplot. Below image of how I want outliers:
Here is a solution: we compute the number of outliers with the output of boxplot, remove the outliers from the graph, and plot the proportion instead.
# 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))