st: Multiple plots, by() option and reversed yaxis scales/labels

I'm having a problem that is driving me nuts and I'd like someone to
confirm for me that I am seeing a bug and would appreciate any
suggestions for a workaround. Forgive me if this has been discussed
previously - I did a search, but results are highly dependent on
having the right vocabulary to describe the problem in the first
place!
First, system and version info:
Stata/SE 10.1 for Windows
Born 01 Oct 2009
Copyright (C) 1985-2009
Total physical memory: 1046596 KB
Available physical memory: 166308 KB
3-user Stata for Windows (network) perpetual license:
Ado-file updates
folder: ***\ado\updates\
names of files: (various)
currently installed: 10 Jun 2010
latest available: 10 Jun 2010
The situation is one where I am plotting a -twoway bar- of counts
overlaid with a -tw scatter- and -tw lowess- of percentages. I
specified the -tw bar- to use yaxis(2) and the other plots to use
yaxis(1). In addition, I am using a -by()- option that creates a 3x3
layout of bygraphs.
My problems is that the yaxis(1) and yaxis(2) are reversed and the
axis title for yaxis(2) appears on the LEFT and no axis title appears
on the right. (this latter is a known problem: see [
http://www.stata.com/statalist/archive/2009-06/msg00363.html ] and [
http://www.stata.com/statalist/archive/2007-11/msg00578.html ] )
The axes are indeed reversed as can be seen by opening the graph
editor and selecting the yaxis labels. One will find:
Object yaxis2[1] is on the LEFT side and object yaxis1[2] is on the RIGHT side
Here are a number of small silly examples to demonstrate the original
problem and approaches I have tried (can be run as a dofile):
******************************************
sysuse auto
collapse (mean) mpg trunk, by(length foreign)
//Produce bygraph with reversed axes and missing yaxis(2) title
tw bar mpg length, yaxis(2) || ///
line trunk length, yaxis(1) || ///
, by(foreign, note("")) name(g1, replace)
//This one has axes in normal orientation and with proper axis titles
tw bar mpg length, yaxis(2) || line trunk length, yaxis(1) ||,
name(g2, replace)
//One can straighten things out by reordering the order of plotting,
but then you have bars plotting over lines which you don't want.
//Produce bygraph with proper axes but bars overwriting lines
tw line trunk length, yaxis(1) || ///
bar mpg length, yaxis(2) || ///
, by(foreign, note("")) name(g3, replace)
/*
The plot thickens (so to speak)
We know that we can induce the proper plotting order for the axis by
specifying the yaxis(1) plot first. Perhaps we could fake Stata out
by doing an invisible plot first to get the axes right, then plot the
bar followed by the line graph as in the following:
*/
tw scatter trunk length, yaxis(1) msymbol(i) || ///
bar mpg length, yaxis(2) || ///
line trunk length, yaxis(1) || ///
, by(foreign, note("")) name(g4, replace)
/*
Much to my surprise, the bars still overlie the lines despite the line
plot coming after. I thought this might just be a further bygraph
problem, but the same happens if you create a graph like so:
*/
tw scatter trunk length, yaxis(1) msymbol(i) || ///
bar mpg length, yaxis(2) || ///
line trunk length, yaxis(1) || ///
, name(g5, replace)
/*
I must surmise that Stata draws the all plots for one axis before
drawing the plots for a second (or higher) axis. This means one could
perhaps (1) establish the proper axis in the first invisible plot
using yaxis(1), (2) plot the bar using yaxis(2) and then (3) plot the
line using yaxis(3) (but turn of the display of that scale) as below:
*/
tw scatter trunk length, msymbol(i) yaxis(1) || ///
bar mpg length, yaxis(2) || ///
line trunk length, yaxis(3) || ///
, yscale( axis(3) off) yscale( axis(2) alt) name(g6, replace)
/*
This would give the result one wants... but will it work in a bygraph
*/
tw scatter trunk length, msymbol(i) yaxis(1) || ///
bar mpg length, yaxis(2) || ///
line trunk length, yaxis(3) || ///
, by(foreign, note("")) ///
yscale( axis(3) off) yscale( axis(2) alt) name(g7a, replace)
/*
This is close, but we now have two yaxes on the left. Not only that,
but they have different scales. I've tried different permutations of
suppressing axes and such but I can't get a single axis on the left.
*/
******************************************
So, at this point, I am officially stumped. yaxis(1) in a bygraph
situation has a mind of its own. (I know I can use the graph editor to
remove the offending scale - that is a last last ditch solution)
I would dearly love to use the functionality provided using bygraph
options - it renders a more compact plot than I can easily do using
-combine- and must fit into a loop where many parameters are being
determined programmatically. However, this bug, if it is one, is
currently a showstopper.
--
David Elliott
Everything is theoretically impossible, until it is done.
Progress is made by lazy men looking for easier ways to do things.
-- Robert A. Heinlein (American science-fiction Writer, 1907-1988)
*
* 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/