Skip to content
Back to formatted view

Raw Message

Message-ID: <000101c3e116$47c5c7a0$78f05a99@msu.montana.edu>
Date: 2004-01-22T18:33:20Z
From: Andy Bunn
Subject: adding mean to boxplot
In-Reply-To: <1074795068.4010123c99310@home.staff.uni-marburg.de>

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