Announcement

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

  • Labeling second axis in a twoway graph with two y-axes

    I am sure this must have been asked (and answered) before but I cannot happen to find any solution that works for me as well.

    I would like to create different labels for the two y-axes I have. I tried the following code:

    Code:
                twoway line stereo_g e, color(edkblue) ytitle("L3 - L1") || line stereo_b e, lpattern(dash) color(edkblue) ytitle("L3 - L1") || line ratio_g e, color(red) yaxis(2) ytitle("(E[Y|T] - E[Y|N])" axis(2)) || line ratio_b e, lpattern(dash) color(red) yaxis(2) ytitle("(E[Y|T] - E[Y|N])" axis(2)) xtitle("...") title("...'") yline(0)
    However, this produces a graph where the left axis appears with the name specified for axis(2) and the right axis appears with no name whatsoever.

    Does anyone know how this might be solved?

    Many thanks in advance,
    Milan

  • #2
    Can you phrase this using a dataset accessible to all? Or use a data example we can use, as FAQ Advice #12 explicitly asks?

    When you say labels, do you mean axis labels or axis titles?

    Meta-rule: terminology elsewhere may be misleading. Only Stata's terminology is canonical on Statalist.

    Comment


    • #3
      Nick admonished for potentially misleading terms. The more precise the terms, the greater the chances of full collaboration, in the Forum and anywhere else.

      Meanwhile, still waiting for further clarification, I suspect your issue can be tackled by using the option yscale(alt). Indeed, a nice trick.

      This can be checked here (Stata tip 93, Stata Journal).

      Being this so, you were right when betting that "this question has been asked and answered before". Therefore, hopefully the solution works for you as well.


      Best regards,

      Marcos

      Comment


      • #4
        Thank you both. What I meant are the title of y-axes. I created the following pseudo-code to illustrate the problem:

        Code:
        clear
        
        input x y1 y2
        1 2.2 320
        2 2.5 443
        3 3.9 565
        4 4.6 744
        end
        
        twoway line y1 x, ytitle("Title y1") || line y2 x, yaxis(2) ytitle("Title y2" axis(2))
        If you run this code you will the graph attached below. The axes are all in place like they should be. I want the y-axis from 2 to 4.5 to appear on the left and the axis from 300 to 800 to appear on the right. This why yscale(alt) option does not work for me, I believe. (Nice tip, though, will definitely keep it in mind.) What is confused in the graph (and thus in the code, but I do not how to fix it) are the titles of the axis. On the left side it should read "Title y1", on the right side "Title y2". Instead there is "Title y2 axis(2)" on the left side and no titel whatsoever on the right side.
        Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	28.7 KB
ID:	1375456


        Comment


        • #5
          Hi Milan,

          This probably isn't any help to you now, nearly a year later, but I came across this thread whilst searching for something else.

          The solution is simply a missing comma between "Title y2" and axis(2). That is, the code should be:

          Code:
          twoway line y1 x, ytitle("Title y1") || line y2 x, yaxis(2) ytitle("Title y2", axis(2))

          Best wishes,

          David.

          Comment


          • #6
            Dear David - I just wanted to say thank you very much for posting your answer to the thread even if it was a year after the initial question; I just used it to generate a line graph with two vertical axes. Best, Felipe

            Comment

            Working...
            X