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.
The legend() option is an option to the graph command, not to a plot
specifation. So it should not be "attached to one of the -line-
commands".
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.
Svend
> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Scott Cunningham
> Sent: Monday, March 13, 2006 8:31 AM
> To: [email protected]
> Subject: st: legend on graph help
>
> I am having trouble adjusting the legend of a simple table. It's a
> two-way graph and I have one variable (SexRatio) which I'm plotting
> separately for Blacks and Whites. The variable has no descriptive
> labeling, so I wanted to change the legend by using the legend-
> ordering command. Is there an obvious mistake here that someone can
> immediately point out? Thanks. -sc
>
> . twoway (order (1 "white sex ratio", 2 "black sex ratio")) (line
> SexRatio age if race==1, lcolor(black) lpattern(dash)) (line SexRatio
> age if race==2, lcolor(black) lpattern(solid)), ytitle(Ratio of Males
> to Females) yscale(range(.65 1.1)) xtitle(Age Cohort) xscale(range(0
> 30)) title(Cohort-Specific U.S. Sex Ratios) caption(All ages are 5-
> year cohorts)
__________________________________________
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C, Denmark
Phone: +45 8942 6090
Home: +45 8693 7796
Email: [email protected]
__________________________________________
*
* 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/