Re: [R] A question about boxplot: mean and median

From: Marc Schwartz <>
Date: Sat 16 Apr 2005 - 02:20:01 EST

On Fri, 2005-04-15 at 08:59 -0700, R_xprt_wannabe wrote:
> Dear List,
> I have worked through the examples given in the help
> on boxplot(). If I am reading it right, only the
> median is produced (as a default), which is
> represented by the horizontal line inside the box.
> What argument do I need to specify if I want to show
> the mean as well?

> Thanks,

There is no standard command using boxplot(). You need to add the means using points():

# Create df with 5 columns
df <-, ncol = 5))

# Now get the mean for each column
means <- apply(df, 2, mean, na.rm = TRUE)

# Plot the boxplot

# Add the means, use pch = 19 to differentiate # between outliers and means
points(1:5, means, pch = 19)

Note that the boxes in boxplot are set at integer values on the x-axis by default (presuming that you are using vertical boxes, otherwise the y axis).

HTH, Marc Schwartz mailing list PLEASE do read the posting guide! Received on Sat Apr 16 02:25:36 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:11 EST