Skip to content
Prev 43110 / 398506 Next

adding mean to boxplot

This will add triangles at the mean value. To change the behavior of
boxplot() to draw means instead of medians would involve rewriting the
bxp() code I believe. You could change the points in the code below to
segments. See ?segments. The archives have quite a few examples of
people modifying the bxp() code so look there and see ?bxp.

     # Load some data
     data(OrchardSprays)
     # Make the boxplot and save the boxplot object
     rb <- boxplot(decrease ~ treatment, data = OrchardSprays)
     # Compute the means
     mean.value <- tapply(OrchardSprays$decrease,
OrchardSprays$treatment, mean)
     # Add them as triangles.
     points(seq(rb$n), mean.value, pch = 17)

HTH, Andy