[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Re: Boxplot w/ 2nd y-axis and mean overlay (statalist-digest V4 #3456)

From   "Nick Cox" <>
To   <>
Subject   st: RE: Re: Boxplot w/ 2nd y-axis and mean overlay (statalist-digest V4 #3456)
Date   Mon, 15 Jun 2009 17:22:52 +0100

I don't know StataCorp's views on this, but I have some of my own. 

A request to add means to box plots is sufficiently common that
StataCorp may give in sooner or later, but what next? Means and
confidence intervals? The trade-off between giving customers what they
want and adding yet more complications to already complicated commands
is not easy. 

Allan didn't spot my deliberate silence on my -stripplot- and second
axes. As -stripplot is a wrapper for -twoway- it would support second
axes, whether to good or not-so-good ends. 

Beware of box plots and log scales for different reasons, spelled out at

The essence of the matter is that box(log()) and log(box()) are not
necessarily identical. 


Allan Reese

Further to Nick Cox's replies, you can add category means to boxplots as
added text, but have to fiddle with the x positions since Stata treats
the category axis differently.
sysuse auto
egen mmpg = mean(mpg), by(foreign)
tab mmpg   // to copy and round the values.
graph box mpg, over(for) text(19.8 21 "*") text(24.8 80 "*")

I don't think that's an adequate solution, and the question has been
raised several times on Statalist.  It would be good to have a "graph
twoway box" plot, so that boxes can be intelligently combined with, eg,
median smoothing lines. 
[Action StataCorp]

I too wanted a second axis on a boxplot last week and found it's not
allowed.  Nick's contemnation of second axes is valid when graphs are
superimposed despite having incompatible units, and I've seen examples
of Procrustean spin to create "correlations" that way.  Multiple scales
on a single graph obstruct relating particular points to the appropriate

But it is perfectly reasonable to have right and left axes with
different labelling and I cannot see why the software should deny
multiple axes at any position. One use would be to label one axis with
the log values and the other with natural numbers; my example would have
labelled one axis with the range for one group (or variable) and the
other axis with another range; you could make nested categories with the
major groupings labelled at the top and the minor ones at the bottom;
although Stata has always drawn axes outside the plotting area,
traditional graphs have axes through the origin which may be within the
plot.  I even tried the graph editor, thinking it would pick up the axis
as an object to copy. (Nah!)  
[Action StataCorp]

From: "Michael Sorice" <>

> I've created a boxplot summarizing three variables over 3 groups. The 
> command line looks like:  graph box A1 A2 B1, over(group)
> Variables A1 & A2 are on the same scale but B1 is on a larger scale.
> Is there a way to put B1 on a 2nd y-axis?  I'd like them all on one
> and readable.  I can only find a 2nd y-axis option for the "twoway" 
> command.
> Additionally, I'd like to add the mean to the boxplot.  

*   For searches and help try:

© Copyright 1996–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index