# [R] Impaired boxplot functionality - mean instead of median

Marc Schwartz (via MN) mschwartz at mn.rr.com
Thu Dec 1 22:30:58 CET 2005

```On Thu, 2005-12-01 at 23:27 +0300, Evgeniy Kachalin wrote:
> Marc Schwartz (via MN) Ð¿Ð¸ÑˆÐµÑ‚:
> >>Marc Schwartz (via MN) Ð¿Ð¸ÑˆÐµÑ‚:
>
> >>So plotmeans is incapable of: boxplot(numerical~fact1+fact2). Is there
> >>any way further?
> >
> >
> > I think that somehow we are talking past each other here.
> >
> > plotmeans() does what it is designed to do, which is to simplify the
> > process of plotting group-wise point estimates and user defined error
> > bars/intervals around the point estimates.
> >
> > In your case, these intervals would be standard deviations around each
> > of the group means as you have indicated.
> >
> > Review the examples in ?plotmeans.
> >
> > As Martin and others have pointed out, you need to remove boxplots from
> > the equation here, as they were not designed to plot means and standard
> > deviations.
> >
>
> Again, what I'm talking about: plotmeans is incapable of analyzing the
> formula. For example, I have two factors: A - a, b, c, and B - d, e, f.
>
> If i plot: boxplot(num~A+B) what do I get? Eight boxes: ad, ae, af, ba,
> be, bf, cd, ce, cf. If I plot: plotmeans(num~A+B) - what do I get?
> Nothing. Because plotmeans cannot combine two factors in various
> combination. Is there a simple way to do it?
>
> Anyway... That's wrong way, all what is neccessary is to have a boxplot
> with mean istead of median. Is there simple way to do it?

If we take SDs out of the picture for the moment, we can do something
like this:

# Do the boxplot as you want using the formula
boxplot(breaks ~ wool + tension, data = warpbreaks)

# Get the means using tapply() with an interaction of the
# factor levels for each group
means <- with(warpbreaks, tapply(breaks,
list(interaction(wool, tension)),
mean, na.rm = TRUE))

# Now add the means to the boxplot, where the
# x axis values are 1:number of groups by default
points(1:length(means), means, pch = 19)

> Statistical software like Statistica 7.0 offers any possible combination
> of what "Boxplot" could mean. Is it possible to have only one
> modification to R's boxplot?
>
> Thank you for kind answers.
> Also please tell me, where should I send replies: to conference adress
> or to those who answer me directly.

Generally best to "reply to all", which gets the message back to the
thread participants quickly as well as the list archive for use by
others during searches.

HTH,

Marc Schwartz

```