Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE: AW: RE: AW: AW: Adding the mean to a boxplot
From
"Nick Cox" <[email protected]>
To
<[email protected]>
Subject
st: RE: AW: RE: AW: AW: Adding the mean to a boxplot
Date
Sun, 9 May 2010 17:48:48 +0100
Fair enough, but good luck doing this elegantly for half-a-dozen means, some of which are very close to each other.
The key point is surely that most people who want this want point symbols (markers) and that can be done, as my earlier posting indicates. In this particular thread that is exactly what the original poster asked for.
Nick
[email protected]
Martin Weiss
" Often it will even be ambiguous which mean goes with which group."
Let`s make it less ambiguous, then:
*************
sysuse bplong, clear
su bp if sex, mean
loc myfirstmean=r(mean)
loc myfirstname "female"
su bp if !sex, mean
graph box bp, over(sex) ///
yli(`r(mean)' `myfirstmean') ///
yla(`myfirstmean' "`myfirstname'" ///
`r(mean)' "male", angle(zero))
*************
Nick Cox
In essence, this is a quick but dirty way to show means. You get one horizontal line for each group mean, which is usually less subtle graphically than people want. Often it will even be ambiguous which mean goes with which group.
To do it better, you need very low-level programming or to use -graph twoway- to construct your box plot. Very full detail on the second way is given in
SJ-9-3 gr0039 . . . . . . . . Speaking Stata: Creating and varying box plots
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N.
J. Cox
Q3/09 SJ 9(3):478--496 (no
commands)
explains how to use egen to calculate the statistical
ingredients needed for box plots and variations of box
plots; shows the use of twoway to then create the plots
This post earlier today expands on some related issues:
<http://www.hsph.harvard.edu/cgi-bin/lwgate/STATALIST/archives/statalist.1005/date/article-332.html>
Martin Weiss
Here is your code:
*************
sysuse bplong, clear
su bp if sex, mean
loc myfirstmean=r(mean)
su bp if !sex, mean
graph box bp, over(sex) ///
yli(`r(mean)' `myfirstmean') yla(`r(mean)' `myfirstmean')
*************
Martin Weiss
Something tells me this is my code, not Nick`s. He might have cited it in his http://www.stata.com/statalist/archive/2009-06/msg00495.html post?
Im Auftrag von [email protected]
I've read:
st: RE: Re: Boxplot w/ 2nd y-axis and mean overlay
>>>From "Nick Cox" <[email protected]>
To <[email protected]>
Subject st: RE: Re: Boxplot w/ 2nd y-axis and mean overlay
Date Sun, 14 Jun 2009 18:16:01 +0100
<snip> <snip>
"Additionally, I'd like to add the mean to the boxplot. Is there a way
to do so?"
***
sysuse bplong, clear
su bp, mean
graph box bp, over(sex) ///
yli(`r(mean)') yla(`r(mean)')
Suppose, instead, I wanted to place a marker (x, for example) representing the mean for males, and a marker representing the mean for females on the boxplot. How could this be accomplished?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/