Skip to content
Prev 199215 / 398503 Next

Adding a symbol/value/overlay to a boxplot in R

On Nov 5, 2009, at 7:12 AM, Marc Giombetti wrote:

            
As per ?boxplot for the 'at' argument:

numeric vector giving the locations where the boxplots should be  
drawn, particularly when add = TRUE; defaults to 1:n where n is the  
number of boxes.


Thus, each box is drawn at x axis values of 1:2 in the case of your  
plots above.

You can use either text() or points() to add characters or symbols to  
the plot:

set.seed(1)
x <- rnorm(100)
grp <- rep(1:2, 50)
boxplot(x ~ grp)

text(1:2, c(-1.5, 1.75), labels = 'x')

points(1:2, c(1, -1), pch = 19)


See ?text and ?points for more information.

HTH,

Marc Schwartz