# Re: Re: st: legend on graph help

 From n j cox To statalist@hsphsun2.harvard.edu Subject Re: Re: st: legend on graph help Date Tue, 14 Mar 2006 13:06:34 +0000

```Everyone's right here, in a sense.

-line- can be a separate command. It is, in that circumstance,
an abbreviation for -twoway line-, which is in turn
an abbreviation for -graph twoway line-.

shows the innards.

In essence, wired-in graph commands are all calls
to -graph-, or wrappers for calls (to calls ( ... ))
to -graph-.

But StataCorp were well aware that users probably don't want
to type

. graph twoway line ...

whenever they want a line plot, hence the convenient
abbreviations.

(FWIW, I always use the || notation. There are plenty
enough parentheses already in a typical -graph- command.)

Nick
n.j.cox@durham.ac.uk

"Svend Juul" <SJ@SOCI.AU.DK>

In a response to Scott C., Scott M. wrote, among other things:

2.  It doesn't appear that the -legend(order())- (or the ytitle,
yscale....)
are attached to one of the -line- commands.

- and suggested:

twoway line mpg price if fore == 0 ,sort lc(blue) lp(dash) ///
|| line mpg price if fore == 1 , sort lc(black)  ///
legend(order(1 "white sex ratio" 2 "black sex ratio"))

---------------------------------------------------------------

Stata graph commands can be complex; I think it is helpful to keep the
terminology straight:

-line- is not a command; it is a plot specification as part of a
-twoway- graph command.

...

Personal view: I think the || notation is a lot less transparent than
the () notation. So I would write the above command:

twoway                                                   ///
(line mpg price if fore == 0 , sort lc(blue) lp(dash)) ///
(line mpg price if fore == 1 , sort lc(black))         ///
,                                                      ///
legend(order(1 "white sex ratio" 2 "black sex ratio"))

Here we have a graph command (twoway) with two plot specifications
(line); each plot specification has options (sort, etc.). The graph
command also has an option: (legend()). ytitle() and yscale() would be
graph options, too. I gave the comma separating the graph command body
from the graph options a line of its own, just for visual clarity.

Stata often can be quite tolerant to deviations from the strict rules,
as Scott M.'s example shows (it actually works), but I think that things
are easier to understand when sticking to the rules.

*
*   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/
```