[S] summary for adding means to boxplots

Karen_Johnson@bdhq.bd.com
Fri, 24 Apr 1998 14:34:45 -0400


From: Karen Johnson@BDX on 04/24/98 02:34 PM
I had posted a question about adding points that represent means
on boxplots. Thanks to all who took the time to reply: Carl Boe,
Chuck Lo Presti, Linda Clark, Sam Buttrey, Rick Traub, Marcus
Davy, Robin Regnier, Frank Harrell, Ha Nguyen, Duncan Murdoch,
and Tim Hesterberg.

Not only is there a way to do it, there are several.

One option is to add the argument plot=F to the command and
assign the ouput to a vector.
> x_boxplot(split(resp, cat), plot=F)
x is a list with the information to generate boxplots yourself
(so you can put the center line wherever you want). This method
has great flexibility, but requires additional coding.

Another option is to leave out the plot=F, but still assign the
output to a vector.
> x_boxplot(split(resp, cat))
x is a vector with the x-coordinates of the center lines. This
acomplishes what I was trying to do easily. Especially as I?m
satisfied with the look of syle.bxp=?att?.

Other options suggested were to use bxp(), boxes(),or bwplot().

This response came from Frank Harrell. I?m still exploring it.
One solution is to use my panel.bpplot function, part of the
Hmisc library in statlib (or on our web page below). E.g.:

bwplot(county ~ age, panel=panel.bpplot)

panel.bpplot shows means with dots and medians with lines.

http://www.med.virginia.edu/medicine/clinical/hes/biostat.htm

And this came from Tim Hesterber (reproduced in its entirety --
it does work on V4).
I ran into this a few years ago. Below are the notes I saved
then, which may help you. Please check them yourself, I don't
have an easy way to check them on V4 on a PC.

Tim Hesterberg
---------

If there are n groups
First center is at: 100(2n+1)/(3n(n+1))
Spacing between centers is: 100(3n+2)/(3n(n+1))
Halfwidth of a box: 100/(6n) * (boxwex/.5)
boxwex does not change centers of boxes, just width. Default is
boxwex=.5. Note that 2*(first center) + (n-1)*(spacing) = 100

Below are some of the commands I used to find this out.

for(i in c(2,4,5,10)){
temp _ boxplot( split(x,1:i))
temp2 _ diff(temp)[1]
print(c(i, 100/temp2, 100/temp[1]))
}
# i 100/temp2
# 2 2.25 = 9/4 = 18/8
# 4 4.285715 = 30/7 = 60/14
# 5 5.294118 = 90/17
# 10 10.3125 = = 330 / 32
# = 3(i+i^2) / (3*i+2)
# i 100/temp[1]
# 2 3.6 = 18/5 = 18/5
# 4 6.666667 = 20/3 = 60/9
# 5 8.181819 = 90/11 = 90/11
# 10 15.71429 = 110/7 = 330/21
# = 3(i+i^2) / (2*i+1)

# First center is at 100(2n+1)/(3n(n+1))
# Spacing is 100(3n+2)/(3n(n+1))

temp _ boxplot( split(x,1:4), width=rep(2,4))
c( diff(temp)[1], temp[1] / diff(temp)[1], temp)
# "width" didn't affect either centers or widths

temp _ boxplot( split(x,1:4), boxwex=1)
c( diff(temp)[1], temp[1] / diff(temp)[1], temp)
# "boxwex=1" affected widths but not centers

temp _ boxplot( split(x,1:2), boxwex=1)
abline(v=temp)
abline(v=temp + 100/(6*2) * 2, col=2)

temp _ boxplot( split(x,1:2), boxwex=2)
abline(v=temp)
abline(v=temp + 100/(6*2) * 4, col=2)

temp _ boxplot( split(x,1:4), boxwex=2)
abline(v=temp)
abline(v=temp + 100/(6*4) * 4, col=2)
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news