Centred bar plots of absolute or relative frequencies
cbarplot yvar [xvar] [weight] [if exp] [in range] [ , [ percent percent(varname) ] yasis xasis format(format) vertical by( by_option) rbaropts(rbar_options) scatter_options ]
cbarplot shows absolute or relative frequencies of yvar as centred bar plots. If xvar is specified, a bar plot is shown for each distinct value of xvar.
By default, each variable is mapped on the fly to an integer variable with values 1 up, but with value labels reflecting the input data, and each bar plot has horizontal bars with absolute or relative frequencies shown as marker labels.
fweights, aweights, iweights and pweights may be specified.
Centred bar plots are often used in archaeology to show frequencies of different kinds of artefact at different levels or ages, sometimes under the title of battleship curves or battleship diagrams (e.g. Doran and Hodson 1975, pp.278-280; Renfrew and Bahn 1991, pp.107-108).
This command will not draw e.g. population pyramids in which each age-group is subdivided by sex. See help on twoway_bar.
percent specifies that frequencies are to be shown as percents of the total.
percent(varlist) specifies that frequencies are to be shown as percents of the totals for the categories of varlist. varlist may only include one or more of yvar, xvar or a variable specified in the by() option.
These two percent options may not be combined.
yasis specifies that the values of yvar should be treated as is. Usually, but not necessarily, yvar should be discrete or already binned in some sense. Either way, the default bar width of 0.95 may now need changing.
xasis specifies that the values of xvar should be treated as is. Usually, but not necessarily, xvar should be discrete or already binned in some sense. Either way, the default bar width of 0.95 may now need changing.
format(format) specifies a format for the marker labels. By default the format is %2.1f, unless all values in the marker labels are integers in which case the default is %2.0f. See help on format if desired.
by() specifies that different graphs be shown for distinct values of the variable specified. See help on by_option for more detail.
vertical specifies that bars are to be drawn vertically. Changing from the default horizontal to vertical will usually imply changing the order of yvar and xvar.
rbaropts(rbar_options) are options of twoway rbar. The defaults include blcolor(blue) bfcolor(none) barw(0.95).
scatter_options are options of twoway scatter. The defaults include mlabpos(0) mlabcolor(blue). Note that setting mlabcolor(bg) would blank out the marker labels.
(data from Doran and Hodson 1975, p.259)
. clear . input levels freqcores freqblanks freqtools 25 21 32 70 24 36 52 115 23 126 650 549 22 159 2342 1633 21 75 487 511 20 176 1090 912 19 132 713 578 18 46 374 266 17 550 6182 1541 16 76 846 349 15 17 182 51 14 4 51 14 13 29 228 130 12 135 2227 729 . end . reshape long freq, i(levels) j(kind) string . cbarplot levels kind [fw=freq] . cbarplot levels kind [fw=freq], percent(levels) . cbarplot levels kind [fw=freq], percent(levels) mlabsize(*.6) . cbarplot levels kind [fw=freq], percent(levels) mlabcolor(bg) rbaropts(bfcolor(blue)) . cbarplot levels [fw=freq], by(kind, row(1)) percent(levels) mlabcolor(bg) rbaropts(bfcolor(blue)) . cbarplot levels [fw=freq], by(kind, row(1)) percent(levels) mlabcolor(bg) rbaropts(bfcolor(blue)) ysc(reverse)
Nicholas J. Cox, Durham University email@example.com
Philip B. Ender drew this kind of graph to my attention and provided helpful comments.
Doran, J.E. and Hodson, F.R. 1975. Mathematics and computers in archaeology. Edinburgh: Edinburgh University Press.
Renfrew, C. and Bahn, P. 1991. Archaeology: Theories, methods and practice. London: Thames and Hudson.
On-line: help for twoway rbar; catplot (if installed); tabplot (if installed)