[R] boxplot - label outliers

Greg Snow Greg.Snow at imail.org
Wed Sep 3 02:20:40 CEST 2008

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.

From: Sherri Heck [sheck at ucar.edu]
Sent: Tuesday, September 02, 2008 5:11 PM
To: Greg Snow
Cc: r-help at r-project.org
Subject: Re: [R] boxplot - label outliers

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
Hope this is clearer.



Greg Snow wrote:
> 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
>> -----Original Message-----
>> From: r-help-bounces at r-project.org
>> [mailto:r-help-bounces at r-project.org] On Behalf Of Sherri Heck
>> Sent: Tuesday, September 02, 2008 3:38 PM
>> To: r-help at r-project.org
>> Subject: [R] boxplot - label outliers
>> 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
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list