Graphs: Titles, Legends, Notes

All commands that follow are options for graphs; i.e., they are placed after the appropriate keyword for a graph and the comma that signals the start of the options part.

Types of title

A title (to be displayed on top of the graph) can be requested with

title("Blood pressure in professors after ten years of service")

A title may extend over several lines; for each line, you will use a new set of quotation marks, as in:

title("Blood pressure in professors" "after ten years of service")

A subtitle may be given as well; just use subtitle in addition to title.

Finally, the axes my be titled as in

xtitle("Age at measurement")
ytitle("Systolic blood pressure RR")

If you don't give titles, the variable labels will by displayed (if they have been defined, of course). To suppress axis titles, use xtitle("") and/or ytitle("")

Font size for titles

The size of titles is changed via the size sub-option. For instance,

xtitle("Time of Measurement", size(medlarge))

will produce a slightly larger font than the default.

help textsizestyle will introduce you to the manifold possibilities of manipulating the size of the title.

Legends

To change Stata's default display of a legend, you can provide labels to be displayed in the legend as follows (but see the following text on "legend(order ...)"):

legend( label (1 "Men") label (2 "Women"))

You can also change the order in which labels are displayed:

legend(order (2 1) label (1 "Men") label (2 "Women"))

In contrast to the former command ("legend(label ...)") this can be simplified to:

legend(order (2 "Women" 1 "Men"))

Note that this command can also be used to suppress one or several categories from the legend; simply omit the respective number(s) and the pertinent label(s). Also note that you need not change the order of labels; in other words, you may use this command simply in place of "legend(label ...)".

Legends normally are placed beneath the plot region. This can be changed with the ring(#), the position(#) and the bplacement(key) options. First,

legend(ring(0))

will place the legend inside the plot; normally it is placed at its bottom, which can be changed with bplacement(key). Possible specifications for "key" are north, neast, east, seast, and so on, and center. Thus,

legend(ring(0) bplacement(neast)

will yield a legend in the top right corner of the plot. Of course it's up to you to decide whether the legend is placed adequately here.

If ring(#) is not specified, or has a value > 0, position of the legend is indicated as a clock position with keyword position(#). Values for # range from 12 (corresponding to north) via 1, 2, 3 (corresponding to east) and so on until 11; a value of 0 signifies the center. (The default, placement below the plot, of course corresponds to a value of 6.)

Finally, a legend you deem unnecessary may be suppressed with the following option:

legend(off)

Notes

A note will typically be displayed in small letters at the left bottom of the graph:

note("Özgul-Harnischfeger data 2004, own calculations")

© W. Ludwig-Mayerhofer, Stata Guide | Last update: 03 Mar 2023