Changing the Look of Elements of the Graph

Lines

In a line chart, you may distinguish different lines by colour or pattern. You may also wish to change the thickness of the line.

Line pattern

The pattern of the line may be changed via option lpattern, such as in

line sales1 sales2 year, lpattern(solid dash)

with the first line being drawn as a solid line and the second as a dashed line. Other pattern styles are dot, dash_dot, shortdash, shortdash_dot, longdash, longdash_dot or blank. The last option is just in case you wish to draw an invisible line for some reason or other. You may also create your own line pattern with the help of a "formula", such as in

line sales1 sales2 year, lpattern("_-." "__#")

You may combine elements _ (underscore = long dash), - (hyphen = medium dash), . (dot = short dash) and # (= small amount of blank space). "l" (small l) will draw a solid line.

Line width

The width, or thickness, of the line may be changed via option lwidth, such as in

line sales1 sales2 year, lwidth(medium)

Apart from some keywords that are available (such as medthin, vthin [for very thin], or thick [which will be too thick in most cases]), you can use numbers, as in lwidth(*1.2), which will multiply the default width by a factor of 1.2, or in lwidth(1.2), with the value in parentheses difficult to interpret in substantial terms (it refers to a percentage of the width or height of the graph, whichever is smaller -- but to translate this into line width is not easy).


Filling colours

Often, you may add an option referring to the colours used to fill bars or boxes.

Histograms

With histograms, try the fcolor() option. You may refer either to a colour, such as in

histogram age, fcolor(green)

or a degree of whiteness, as in

histogram age, fcolor(gs16)

Find more about filling colours by typing help colorstyle.

Bar charts

graph bar (percent), over(education) bar(1, bfcolor(white) blcolor(black))

will yield white, i.e. blank, bars that are delineated by black lines. That is, bfcolor refers to the the bar, whereas blcolor may stand for "bar line".

Note, however, that the look of the bar can be modified in other ways as well, and these interact with bfcolor and blcolor. These modifications come from the intens[ity] and lintens[ity] options (for intensity [of color] and line intensity). These options refer to the overall graph, i.e., they are not associated with a specific bar (bar(1, ...) but stand alone. intens(0) will reduce the intensity of the filling colour to zero (i.e., to white), whereas intens(255) will yield the full flavour. intens(*#) will change the intensity compared to the default value. intens(*.5) will yield half the intensity and intens(*2) will double it.

The same holds for lintens[ity], but note that whatever you do with this option, it will be overriden by a blcolor option associated with a bar, as described in the example above.

Finally, the thickness of the line that outlines the bar can be influenced with lwidth(), which is used as a sup-option to the bar() option, just like bfcolor or blcolor. For a description, see the first section (on line charts) of this entry.

Box plots

As far as box plots are concerned, I'm not certain whether (and if so, how) you may change the colour of the box. However, the intensity() option allows you to regulate the amount of colour used for the box. intensity(0) will deliver a white box, with a maximum of 100 for the highest intensity.


Adding elements to your graphs

A horizontal line at a given value of y, say, 1.5, may be added with option

yline(1.5)

Several numbers may be enclosed within the parentheses, producing several lines.

A vertical line at a given value of x, say, 3, not suprisingly is added with option

xline(3)

Again, several values may be enclosed within the parentheses, producing several lines.

© W. Ludwig-Mayerhofer, Stata Guide | Last update: 14 Apr 2017