Announcement

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

  • Suppress legend in twoway graph for some scatter

    Hello everybody,

    I have a twoway graph overlaying two scatterplots and one fitted line. I want to suppress the legend for the fitted line but keep it for the two scatterplots.

    My code looks like this:

    Code:
    sysuse auto, clear
    separate price, by(foreign)
    tw (scatter price1 mpg) (scatter price0 mpg) (lfit price mpg)
    So I want to keep the colour legend for the dots (corresponding to the 2 outcomes of the variable foreign) but without the legend for the fitted line.

    The most natural approach to me was to use legend(off) within the lfit parentheses like below, but it deletes the whole legend.
    Code:
    tw (scatter price1 mpg) (scatter price0 mpg) (lfit price mpg, legend(off))
    Thank you for your help,
    Antonin


  • #2
    Code:
    legend(order(1 2))

    Comment


    • #3
      Thank you Nick, it works just fine.

      For future users, here is the full command. Any of these two should do:

      Code:
      tw (scatter price1 mpg) (scatter price0 mpg) (lfit price mpg, legend(order (1 2)))
      tw (scatter price1 mpg) (scatter price0 mpg) (lfit price mpg), legend(order (1 2))

      Comment

      Working...
      X