Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Better control over multiple axes

    Consider
    Code:
    sysuse auto
    twoway (line  length price, yaxis(1) sort) (line  weight price, yaxis(2) sort)  // GRAPH 1
    twoway (line  length price, yaxis(2) sort) (line  weight price, yaxis(1) sort)  // GRAPH 2
    I find it irritating and counter-intuitive that in both of these graphs, length is on the left Y-axis, even though in the first graph it is specified as yaxis(1) and in the second yaxis(2). This is because the length plot is specified before the weight plot. But I choose the ordering of plots based on which plot I wanted to be underneath the other plot (so it is (partially) covered when the plots overlap). This may conflict with the ordering I want for the axes. Indeed it is quite likely: I normally specify the most "important" plot last, so that it is drawn on top of the other plots, but then if there are multiple Y axes it is associated with the less-prominent right-hand axis rather than the standard left-hand y axis.

    Is there a way around this? Or what do people think about asking Stata to make axis placement reflect the axis number, not the plot ordering?

  • #2
    -yaxis()- is a plot option, and the plots in twoway are defined by the order of plots in the command line. So -yaxis(1)- and -yxis(2)- do not refer to plot 1 and plot 2. They might just as well be -yaxis(5)- and -yaxis(7)-.

    Code:
    help axis_choice_options
    Vince Wiggins has a clever workaround here that involves the -alt- suboption of -yscale()-.

    Code:
    sysuse auto, clear
    twoway (line  length price, yaxis(2) yscale(alt) sort) ///
    (line  weight price, yaxis(1) sort), yscale(alt axis(2))

    Comment


    • #3
      Thank you that works great! Andrew Musau as usual to the rescue.

      One small clarification is that I was not proposing that -yaxis(1)- and -yxis(2)- should refer to plot 1 and plot 2, but that they should refer to axis locations -- something like odd numbers produce left hand side axes, while even numbers produce right hand side axes.

      But anyway, your suggestion works for me. Thank you.

      Comment

      Working...
      X