help for multidot

Multiple panel dot charts

multidot
yvars
[if exp]
[in range]
,
over(varname)
[
sort(varlist)
descending
missing
by(by_options)
recast(twoway_command)
{
separate
|
sepby(varname)
}
savedata(filename [, replace])
twoway_options
]

Description

multidot plots two or more yvars for different levels of a
(numeric or string) identifier variable specified by the required
over() option. Each yvar is by default plotted in a dot
chart in a separate panel using twoway scatter. A common
application is to plot variables measured in different units and/or on
very different scales.

multidot works with a temporarily restructured dataset in which
different yvars are stacked into one. The graph then is
based on use of twoway, by(). The original variable labels (or, if
labels are not defined, variable names) become the value labels of the
stacking variable.

By default

The vertical axis shows rank, with low ranks at the bottom
and high ranks at the top. The order can be reversed using the
descending option.

Rank is defined by the sort order
of yvars, so that ordering of values from top to bottom of the
display is in the first instance determined by the first variable
mentioned, with any ties broken in the usual way according to the values
of other variables. The option sort() may be used to specify
another sort order.

The recast() option opens the door to using the same design for
other kinds of plots, for example bar charts. In each such case, the
command is based on some other twoway plot.

Default options include
by(_stack, note("") xrescale subtitle(, fcolor(green*0.2) xtitle("") yla(, grid glw(vthin) glc(gs12) valuelabel ang(h) tl(0))) for all cases;
ms(Oh) mc(dkgreen) for default dot charts;
and horizontal barw(0.7) blcolor(dkgreen) bfcolor(none) base(0) for bar
charts.

It perhaps deserves emphasis that although plots produced by
multidot have much of the look and feel of those produced by
graph dot or graph hbar they are produced entirely by
twoway. Talking of yvars is a nod to this hybrid flavour:
as with graph dot and its siblings, the variables concerned are
in essence regarded as outcomes or responses, even when they are plotted
horizontally.

Options

over() specifies an identifier variable defining distinct
or unique observations to be shown on the vertical axis. This is a
required option.

sort() specifies one or more variables defining the sort
order of observations in the graph. This option may be used to override
the default ordering, as when a user is perverse enough to prefer
alphabetical order by name or desires an idiosyncratic order defined by
a previously constructed variable.

descending reverses sort order on the vertical axis from
the default.

missing specifies that observations with some missing values on
yvars be included in the sample. The default is to ignore
observations with any missing values.

by() specifies options of the by() option. Note
that _stack produced temporarily by the program is already wired
in as varlist for a by() option.

recast() specifies that the graph be recast to another
twoway type. See help on advanced options.

separate specifies that data in different panels for the various
yvars should be shown differently. There is then scope for
specifying different marker symbols, marker colours, and so forth.

sepby() specifies that data be shown differently according to
the distinct values of the variable named. There is then scope for
specifying different marker symbols, marker colours, and so forth.

separate and sepby() may not be combined. sepby()
option is not allowed with recast().

savedata() specifies that data used to produce the graph be
saved as a separate dataset. The axis variables will be named _y
and _rank. separate or sepby() is ignored for this
purpose.

twoway_options are options of twoway.

Examples

. sysuse auto, clear

. multidot price mpg if foreign, over(make)

. multidot price mpg if foreign, over(make) recast(bar)

. multidot price mpg if foreign, over(make) recast(bar) desc

. multidot price mpg weight if foreign, over(make) recast(bar) desc by(row(1)) xla(, ang(v))

. multidot price mpg weight if foreign, over(make) recast(bar) desc by(row(1)) xla(, ang(v)) blcolor(blue)

. multidot price mpg weight if foreign, over(make) desc by(row(1)) xla(, ang(v)) recast(dropline) lw(thick) lc(orange_red) mc(orange_red)

. multidot price mpg weight if foreign, over(make) desc by(row(1)) xla(, ang(v)) recast(spike) lw(vthick)

. multidot price mpg weight if foreign, over(make) desc by(row(1)) xla(, ang(v)) recast(spike) lw(vthick) lc(orange_red*0.5)

. multidot price mpg weight if foreign, over(make) sort(make) desc by(row(1))

. foreach v in mpg turn trunk headroom {

. local lbl`v' "`: var label `v''"

. }

. collapse mpg turn trunk headroom, by(rep78)

. foreach v in mpg turn trunk headroom {

. label var `v' "`lbl`v''"

. }

. multidot mpg turn trunk headroom, over(rep78) sort(rep78) desc by(row(1)) ms(O)

. clear

. input str13 country budget active reservists

. "United States" 604.5 1347 865

. "India" 51.1 1395 1155

. "China" 145.0 2183 510

. "Malaysia" 4.2 109 52

. "Singapore" 10.2 73 313

. "Vietnam" 4.0 482 5000

. "Indonesia" 8.2 396 400

. "Philippines" 2.5 125 131

. "Taiwan" 9.8 215 1657

. "S. Korea" 33.8 630 4500

. "Japan" 47.3 247 56

. "N. Korea" . 1190 600

. "Australia" 24.2 58 21

. end

. label var budget "Defence budget ($ billion)"

. label var active "Active forces ('000)"

. label var reservists "Reservists ('000)"

. note : "Source: The Economist, April 22 2017"

. note : "Their source: IISS, 2016"

. multidot b a r, over(c) by(row(1) compact) recast(hbar) subtitle(, size(medsmall)) ytitle("") missing bfcolor(eltgreen)

. multidot a r b, over(c) by(row(1) compact) recast(hbar) subtitle(, size(medsmall)) ytitle("") xla(#5, labsize(small)) missing bfcolor(eltgreen)

. clear

. input float order str2 id float(area population HDI GDPpc area2 pop2 GDPpc2)

. 1 "BW" 35752 11023425 .953 44886 35.752 11.023425 44.886

. 2 "BY" 70552 12997204 .944 45810 70.552 12.997204 45.81

. 3 "BE" 892 3613495 .944 38032 .892 3.613495 38.032

. 4 "BB" 29479 2504040 .913 27675 29.479 2.50404 27.675

. 5 "HB" 419 681032 .952 49570 .419 .681032 49.57

. 6 "HH" 755 1830584 .977 64576 .755 1.830584 64.576

. 7 "HE" 21115 6243262 .947 44804 21.115 6.243262 44.804

. 8 "NI" 47609 7962775 .922 36164 47.609 7.962775 36.164

. 9 "MV" 23180 1611119 .908 26560 23.18 1.611119 26.56

. 10 "NW" 34085 17912134 .935 38645 34.085 17.912134 38.645

. 11 "RP" 19853 4073679 .924 35455 19.853 4.073679 35.455

. 12 "SL" 2569 994187 .926 35460 2.569 .994187 35.46

. 13 "SN" 18416 4081308 .926 29856 18.416 4.081308 29.856

. 14 "ST" 20446 2223081 .905 27221 20.446 2.223081 27.221

. 15 "SH" 15799 2889821 .917 32342 15.799 2.889821 32.342

. 16 "TH" 16172 2151205 .917 28747 16.172 2.151205 28.747

. end

. label var area "Area (km2)"

. label var population "Population 2017"

. label var HDI "Human Development Index 2017"

. label var GDPpc "GDP pc 2017 (Euro)"

. label var area2 "Area (000 km2)"

. label var pop2 "Population 2017 (m)"

. label var GDPpc2 "GDP pc 2017 (000 Euro)"

. multidot HDI GDPpc2 , over(id) ytitle("")

. multidot HDI GDPpc2 , over(id) separate ms(O D) mc(orange blue) ytitle("")

. gen isBY = id == "BY"

. multidot HDI GDPpc2 , over(id) sepby(isBY) ms(O D) mc(orange blue) ytitle("")

Author

Nicholas J. Cox, University of Durham, U.K.

n.j.cox@durham.ac.uk

Acknowledgments

A suggestion from Eric A. Booth on
Statalist
led to the separate and sepby() options.

Also see

On-line: help for graph dot, graph bar