Skip to content

boxplot - label outliers

5 messages · Sherri Heck, Greg Snow, Henrique Dallazuanna

#
Hi All-

I have 24 boxplots on one graph.  I do not have the whiskers extending 
to the outliers, but I would like to label the maximum value of each 
outlier above the whiskers.  I have the stats but am having trouble 
figuring out how to label the whiskers.

Any suggestions would be great!

sherri
#
Are you trying to find the values of the outliers? Or just how to add the text to the plot in the appropriate place? Or both?

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
(801) 408-8111
#
Hi Greg,

I have the values of the outliers from the boxplot stats.  I am just 
having a difficult time adding the values to the plot in the appropriate 
places.
Hope this is clearer.

Thanks!

sherri
Greg Snow wrote:
#
OK, there are a couple of approaches that you can take.

A simple approach is to use the 'locator' function to find the coordinates where you want to put the numbers by clicking on the plot, then use that result with the 'text' function.  This is fine for a single plot with just a few outlier to add, but does not work if you want the process to be fully automated.

You can use the boxplot function with argument 'plot=FALSE' to compute the stats, then pass that to the 'bxp' function to do the actual plotting.  The bxp function has an 'at' argument so that you can specify where you want the individual boxes plotted at (x-coordinate), then use that information along with the 'text' function to plot the values.  Or use the bxp function again, but capture the return value which is the x-coordinates of the boxes.

If you want to plot the numbers along the top or bottom of the plotting area, then 'par("usr")' returns a vector of length 4, the last 2 values are the y-coordinates for the bottom of the plotting area and the top respectively.

You can use the function 'updateusr' from the TeachingDemos package to change the coordinates of a plot after the fact so that the x-coordinates match with what you expect (using information from locator or
par('usr')), but this is probably overkill compared to the above methods.

Hope this helps, if it doesn't, give a bit more detail.