Skip to content
Prev 154828 / 398503 Next

boxplot - label outliers

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.