The order() suboption makes label() redundant


Before, I thought that the order() suboption for graphic legend() option is only used to specify which legend keys will be shown and in which order you want them to be displayed. But recently I learned that it also makes the label() suboption redundant. To illustrate, we use census.dta which is installed with Stata.

sysuse census.dta, clear

#delimit ;
tw (scatter  marriage divorce, mlabel(state2))
(lfit marriage divorce),
ytitle(“Number of marriages”)
ylabel(, angle(0))
legend(label(2 “Fitted regression line”) order(2) ring(0) pos(5))
;
#delimit cr

#delimit ;
tw (scatter  marriage divorce, mlabel(state2))
(lfit marriage divorce),
ytitle(“Number of marriages”)
ylabel(, angle(0))
legend(order(2 “Fitted regression line”) ring(0) pos(5))
;
#delimit cr

Both commands above will result in the same graph (see below). The legend key for the first- tw- plot, which by default is the y-variable name or label (if exists),  is not displayed.



Another advantage of using order() over label() is that label(), by default, is limited to hold 15 keys.


Thanks to Derek Wagner of Stata for his reply to our query on maximum number of keys using label() and for pointing out the capabilities of order().
Before, I thought that the order() suboption for graphic legend() option is only used to specify which legend keys will be shown and in which order you want them to be displayed. But recently I learned that it also makes the label() suboption redundant. To illustrate, we use census.dta which is installed with Stata. 

sysuse census.dta, clear

#delimit ;
tw (scatter  marriage divorce, mlabel(state2))
(lfit marriage divorce),
ytitle(“Number of marriages”)
ylabel(, angle(0))
legend(label(2 “Fitted regression line”) order(2) ring(0) pos(5))
;
#delimit cr

#delimit ;
tw (scatter  marriage divorce, mlabel(state2))
(lfit marriage divorce),
ytitle(“Number of marriages”)
ylabel(, angle(0))
legend(order(2 “Fitted regression line”) ring(0) pos(5))
;
#delimit cr

Both commands above will give the same graph.

Another advantage of using order() over label() is that label(), by default, is limited to hold 15 keys.

______________________

Thanks to Derek Wagner of Stata for his reply to our query on maximum number of keys using label().

Leave a Reply