Announcement

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

  • How to add the title for the second y-axis in graph when -by()- is used

    Dear Statalist,

    I have a problem in adding the title for the second y-axis. If I do not use -by()-, stata will display the title for the extra y-axis. The problem is when I use -by()- and ytitle("name",axis(2)) I cannot get the graph with the title of the extra y-axis displayed.

    Data I used:
    Code:
     sysuse auto, clear
     sort foreign weight
    If I typed,
    Code:
    twoway line price weight || line length weight, yaxis(2)
    , the title of the extra y-axis length can be displayed.

    If I however used -by()- and typed,
    Code:
    twoway line price weight, by(foreign) || line length weight, yaxis(2)
    , stata by default suppressed the title for extra y-axis length.

    I cannot display the title for y-axis length, even if I followed the instruction of stata documentation and typed
    Code:
    twoway line price weight, by(foreign) || line length weight, yaxis(2) ytitle("Length", axis(2))
    .

    If I used r2title option by typing
    Code:
    twoway line price weight, by(foreign) || line length weight, yaxis(2) r2title("Length")
    , I will have title show up in both two plots (foreign and domestic). This is not what I want either.

    Thus I wonder whether there is one way to make the left plot have title for the first y-axis and right plot have title for the extra y-axis.


    Kind regards,
    Yugen


























  • #2
    Code:
    twoway line price weight, by(foreign, r2title("Length")) || line length weight, yaxis(2)

    Comment


    • #3
      Thanks Scott, it works!

      Comment

      Working...
      X