My idea is that Stata [sic] gave you what you asked
for. Without knowing what you want -- and that is
different -- I can't comment easily. Perhaps you
want something like
. twoway bar mpg rep78, yaxis(1 2) yla(18 "1.8" 28 "2.8", axis(2))
|| line mpg rep78, yla(20 30, axis(1))
Nick
[email protected]
Peter Uhrmacher
> adding yaxis(1 2) was part of the solution, I only had yaxis(2) and
> axis(2) in my code. However, there is still a minor problem left:
>
> If I add
>
> gen mpg2=mpg/10
>
> to your example
>
> and then do this (i.e. just use the newly created mpg2 instead of mpg
> for the bars and divide the labels (i.e. the range) by 10 as well)
>
> twoway bar mpg2 rep78, yaxis(1 2) yla(1.8(.2)2.8, axis(2)) ||
> line mpg
> rep78, yla(20 30, axis(1))
>
> STATA uses the same range of values for the left and right
> axis. Any ideas?
Peter Uhrmacher
> Thx a lot, the yaxis(1 2) was the solution, I only had yaxis(2) and
> axis(2)...!
Nick Cox wrote:
> > There is no concrete code to comment on here. I did this:
> > . sysuse auto, clear (1978 Automobile Data)
> >
> > . collapse mpg, by(rep78)
> > . l
> >
> > +-----------------+
> > | rep78 mpg |
> > |-----------------|
> > 1. | 1 21 |
> > 2. | 2 19.125 |
> > 3. | 3 19.4333 |
> > 4. | 4 21.6667 |
> > 5. | 5 27.3636 |
> > |-----------------|
> > 6. | . 21.4 |
> > +-----------------+
> >
> > . twoway bar mpg rep78, yaxis(1 2) yla(18(2)28, axis(2))
> || line mpg
> rep78, yla(20 30, axis(1))
> >
> > and the line plot is on top of the bar plot, and I have
> two separate
> axes. Does that help?
Peter Uhrmacher
> it seems that I am unable to solve a rather simple
> problem... but I
> hope you can. What I would like to have is a "graph twoway"
> with a line
> plot and a bar plot. the line plot is supposed to use yaxis1, the bar
> plot is supposed to use yaxis2. at the same time, the bar plot is
> supposed to appear in the background (so that the lines
> appear on top of
> it). however, whatever I try it seems that the plots that use
> yaxis2 are
> always put on top of the others that use yaxis1... (which in my case
> means that the line plot is hidden behind the bars). Is there a
> solution? I'm sure there is.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/