📄 graph_box.hlp
字号:
{pmore}
Specify {cmd:intensity(0)} if you do not want the box filled at all.
If you are using a scheme that draws the median line in the background
color such as {cmd:s2mono}, also specify option {cmd:medtype(line)}
to change the median line to be in the color of the outline of the box.
{phang}
{cmd:lintensity(}{it:#}{cmd:)}
and
{cmd:lintensity(*}{it:#}{cmd:)}
specify the intensity of the line used to outline the box.
{cmd:lintensity(}{it:#}{cmd:)} specifies the intensity, and
{cmd:lintensity(*}{it:#}{cmd:)} specifies the intensity relative to the
default.
{pmore}
By default, the box is outlined at the same intensity at which it is
filled or at an amplification of that, which depending on your chosen
scheme; see {help schemes}. If you want the box outlined in the
darkest possible way, specify {cmd:intensity(255)}. If you wish simply to
amplify the outline, specify {cmd:intensity(*}{it:#}{cmd:)}, {it:#}>1, and
if you wish to attenuate the outline, specify
{cmd:intensity(*}{it:#}{cmd:)}, {it:#}<1.
{phang}
{cmd:medtype()},
{cmd:medline()}, and
{cmd:medmarker()}
specify how the median is to be indicated in the box.
{pmore}
{cmd:medtype(line)} is the default. A line is drawn across the box at
the median. In this case, options {cmd:medline()} and {cmd:medmarker()}
are irrelevant.
{pmore}
{cmd:medtype(cline)} specifies a custom line be drawn across the box at
the median. The default custom line is usually of a different color.
You can, however, specify option {cmd:medline(}{it:line_options}{cmd:)}
to control exactly how the line is to look;
see {it:{help line_options}}.
{pmore}
{cmd:medtype(marker)} specifies a marker be placed in the box at the
median. In this case, you may also specify option
{cmd:medmarker(}{it:marker_options}{cmd:)} to specify the look of the
marker; see {it:{help marker_options}}.
{phang}
{cmd:cwhiskers},
{cmd:lines(}{it:line_options}{cmd:)},
{cmd:alsize(}{it:#}{cmd:)}, and
{cmd:capsize(}{it:#}{cmd:)}
specify the look of the whiskers.
{pmore}
{cmd:cwhiskers} specifies that custom whiskers are desired. The
default custom whiskers are usually dimmer, but you may specify
option {cmd:lines(}{it:line_options}{cmd:)} to specify how the
custom whiskers are to look; see {it:{help line_options}}.
{pmore}
{cmd:alsize(}{it:#}{cmd:)} and {cmd:capsize(}{it:#}{cmd:)} specify the
width of the adjacent line and the height of the cap on the adjacent line.
You may specify these options whether or not you specify
{cmd:cwhiskers}. {cmd:alsize()} and {cmd:capsize()} are specified in
percentage-of-box-width units; the defaults are {cmd:alsize(67)} and
{cmd:capsize(0)}. Thus the adjacent lines extend two-thirds the width of
a box and, by default, have no caps. Caps refer to whether the whiskers
look like
this or this
{c TT} {c TLC}{c TT}{c TRC}
{c |} {c |}
{c TLC}{c BT}{c TRC} {c TLC}{c BT}{c TRC}
{c |}-{c |} {c |}-{c |}
{c BLC}{c TT}{c BRC} {c BLC}{c TT}{c BRC}
{c |} {c |}
{c BT} {c BLC}{c BT}{c BRC}
{pmore}
If you want caps, try {cmd:capsize(5)}.
{phang}
{cmd:marker(}{it:#}, {it:marker_options} {it:marker_label_options}{cmd:)}
specifies the marker to be used to display the outside values.
See {it:{help marker_options}} and {it:{help marker_label_options}}.
{phang}
{cmd:outergap(*}{it:#}{cmd:)} and
{cmd:outergap(}{it:#}{cmd:)}
specify the gap between the edge of the graph to beginning of the first
box and the end of the last box to the edge of the graph.
{pmore}
{cmd:outergap(*}{it:#}{cmd:)} specifies that the default be modified.
Specifying {cmd:outergap(*1.2)} increases the gap by 20%, and
specifying {cmd:outergap(*.8)} reduces the gap by 20%.
{pmore}
{cmd:outergap(}{it:#}{cmd:)} specifies the gap as a
percentage-of-box-width units. {cmd:outergap(50)} specifies that the gap
be half the box width.
{phang}
{cmd:boxgap(}{it:#}{cmd:)}
specifies the gap to be left between {it:yvar} boxes as a
percentage-of-box-width units. The default is {cmd:boxgap(33)}.
{pmore}
Note that {cmd:boxgap()} affects only the {it:yvar} boxes. If you want
to change the gap for the first, second, or third {cmd:over()}
groups, specify the {it:over_subopt} {cmd:gap()} inside the
{cmd:over()} itself; see
{hi:Suboptions for use with over() and yvaroptions()} below.
{title:legending_options}
{phang}
{it:legend_option}
allows you to control the legend.
If more than one {it:yvar} is specified, a legend is produced.
Otherwise, no legend is needed because the {cmd:over()} groups are
labeled on the categorical {it:x} axis.
See {it:{help legend_option}}, and see
{help graph box##remarks3:Treatment of multiple yvars versus treatment of over() groups}
under {hi:Remarks} below.
{phang}
{cmd:nolabel}
specifies that, in automatically constructing the legend, the variable
names of the {it:yvars} be used in preference to their labels.
{phang}
{cmd:yvaroptions(}{it:over_subopts}{cmd:)}
allows you to specify {it:over_subopts} for the {it:yvars}. This is
very rarely done.
{phang}
{cmd:showyvars}
specifies that, in addition to building a legend, the identities of the
{it:yvars} be shown on the categorical {it:x} axis. If
{cmd:showyvars} is specified, it is typical to also specify
{cmd:legend(off)}.
{title:axis_options}
{phang}
{cmd:yalternate} and {cmd:xalternate}
switch the side on which the axes appear.
{pmore}
Used with {cmd:graph} {cmd:box}, {cmd:yalternate} moves the numerical
{it:y} axis from the left to the right; {cmd:xalternate} moves the
categorical {it:x} axis from the bottom to the top.
{pmore}
Used with {cmd:graph} {cmd:hbox}, {cmd:yalternate} moves the numerical
{it:y} axis from the bottom to the top; {cmd:xalternate} moves the
categorical {it:x} axis from the left to the right.
{pmore}
If your scheme by default puts the axes on the opposite sides, then
{cmd:yalternate} and {cmd:xalternate} reverse their actions.
{phang}
{cmd:yreverse}
specifies that the numerical {it:y} axis have its scale reversed
so that it runs from maximum to minimum.
{phang}
{it:axis_scale_options}
specify how the numerical {it:y} axis is scaled and how it looks; see
{it:{help axis_scale_options}}. There you will also see
option {cmd:xscale()} in addition to {cmd:yscale()}.
Ignore {cmd:xscale()}, which is irrelevant in the case of box plots.
{phang}
{it:axis_label_options}
specify how the numerical {it:y} axis is to be labeled.
The {it:axis_label_options} also allow you to add and suppress
grid lines;
see {it:{help axis_label_options}}.
There you will see that, in addition to options
{cmd:ylabel()}, {cmd:ytick()}, ..., {cmd:ymtick()},
options {cmd:xlabel()}, ..., {cmd:xmtick()} are allowed. Ignore the
{cmd:x*()} options, which are irrelevant in the case of box plots.
{phang}
{cmd:ytitle()}
overrides the default title for the numerical {it:y} axis; see
{it:{help axis_title_options}}. There you will also find option
{cmd:xtitle()} documented, which is irrelevant in the case of box plots.
{title:title_and_other_options}
{phang}
{cmd:text()}
adds text to a specified location on the graph; see
{it:{help added_text_option}}. The basic syntax of {cmd:text()} is
{cmd:text(}{it:#_y} {it:#_x} {cmd:"}{it:text}{cmd:")}
{pmore}
{cmd:text()} is documented in terms of twoway graphs. When used with
box plots, the "numeric" {it:x} axis is scaled to run from 0 to 100.
{phang}
{cmd:yline()}
adds horizontal ({cmd:box}) or vertical ({cmd:hbox}) lines at specified
{it:y} values; see {it:{help added_line_options}}. The {cmd:xline()}
option, also documented there, is irrelevant in the case of box plots.
If your interest is in adding grid lines, see
{it:{help axis_label_options}}.
{phang}
{it:aspect_option}
allows you to control the relationship between the height and width of
a graph's plot region; see {it:{help aspect_option}}.
{phang}
{it:std_options}
allow you to add titles, control the graph size, save the graph on
disk, and much more; see {it:{help std_options}}.
{phang}
{cmd:by(}{it:varlist}{cmd:, ...)}
draws separate plots within a single graph; see {it:{help by_option}}
and see {help graph box##remarks8:Use with by()} under {hi:Remarks} below.
{title:Suboptions for use with over() and yvaroptions()}
{phang}
{cmd:total}
specifies that, in addition to the unique values of
{cmd:over(}{it:varname}{cmd:)}, a group be added reflecting all
the observations. When multiple {cmd:over()}s are specified,
{cmd:total} may only be specified in one of them.
{phang}
{cmd:relabel(}{it:#} {cmd:"}{it:text}{cmd:"} ...{cmd:)}
specifies text to override the default category labeling.
See the description of the {cmd:relabel()} option in
{helpb graph_bar} for more information about this very useful option.
{phang}
{cmd:label(}{it:cat_axis_label_options}{cmd:)}
determines other aspects of the look of the category labels on the {it:x}
axis. With the exception of {cmd:label(labcolor())} and
{cmd:label(labsize())}, these options are seldom specified; see
{it:{help cat_axis_label_options}}.
{phang}
{cmd:axis(}{it:cat_axis_line_options}{cmd:)}
specifies how the axis line is rendered. This is a rarely specified
option. See {it:{help cat_axis_line_options}}.
{phang}
{cmd:gap(}{it:#}{cmd:)} and
{cmd:gap(*}{it:#}{cmd:)}
specify the gap between the boxes in this {cmd:over()} group.
{cmd:gap(}{it:#}{cmd:)} is specified in percentage-of-box-width units, so
{cmd:gap(67)} means two-thirds the width of a box.
{cmd:gap(*}{it:#}{cmd:)} allows modifying the default gap.
{cmd:gap(*1.2)} would increase the gap by 20%, and {cmd:gap(*.8)} would
decrease the gap by 20%.
{pmore}
To understand the distinction between
{cmd:over(}...{cmd:,} {cmd:gap())} and option {cmd:boxgap()}, consider
{phang3}
{cmd:. graph box before after, boxgap(}...{cmd:) over(sex, gap(}...{cmd:))}
{pmore}
{cmd:boxgap()} sets the distance between the before and after boxes.
{cmd:over(,gap())} sets the distance between the boxes for males and
females. Similarly, in
{cmd:. graph box before after, boxgap(}...{cmd:)}
{cmd:over(sex, gap(}...{cmd:))}
{cmd:over(agegrp, gap(}...{cmd:))}
{pmore}
{cmd:over(sex, gap())} sets the gap between males and females, and
{cmd:over(agegrp, gap())} sets the gap between age groups.
{phang}
{cmd:sort(}{it:varname}{cmd:)} and
{cmd:sort(}{it:#}{cmd:)}
control how the boxes are ordered. See {hi:How boxes are ordered}
and {help graph box##remarks5:Reordering the boxes} under {hi:Remarks}
below.
{pmore}
{cmd:sort(}{it:varname}{cmd:)} puts the boxes in the order of {it:varname};
see {help graph box##remarks6:Putting the boxes in a prespecified order}
under {hi:Remarks} below.
{pmore}
{cmd:sort(}{it:#}{cmd:)} puts the boxes in order of their medians.
{it:#} refers to the {it:yvar} number on which the ordering should be
performed;
see {help graph box##remarks7:Putting the boxes in median order} under
{hi:Remarks} below.
{phang}
{cmd:descending}
specifies that the order of the boxes{hline 2}default or as specified
by {cmd:sort()}{hline 2}be reversed.
{title:Remarks}
{pstd}
Remarks are presented under the headings
{help graph box##remarks1:Introduction}
{help graph box##remarks2:Examples of syntax}
{help graph box##remarks3:Treatment of multiple yvars versus treatment of over() groups}
{help graph box##remarks4:How boxes are ordered}
{help graph box##remarks5:Reordering the boxes}
{help graph box##remarks6:Putting the boxes in a prespecified order}
{help graph box##remarks7:Putting the boxes in median order}
{help graph box##remarks8:Use with by()}
{help graph box##remarks9:History}
{pstd}
Also see {helpb graph bar}. Most of what is said there applies equally
well to box charts.
{marker remarks1}{...}
{title:Introduction}
{pstd}
{cmd:graph} {cmd:box} draws vertical box plots:
{cmd}. sysuse bplong, clear
. graph box bp, over(when) over(sex)
ytitle("Systolic blood pressure")
title("Response to Treatment, by Sex")
subtitle("(120 Preoperative Patients)" " ")
note("Source: Fictional Drug Trial, StataCorp, 2003"){txt}
{it:({stata "gr_example2 grbox1":click to run})}
{* graph grbox1}{...}
{pstd}
{cmd:graph} {cmd:hbox} draws horizontal box plots:
{cmd}. sysuse nlsw88, clear
. graph hbox wage, over(ind, sort(1)) nooutside
ytitle("")
title("Hourly wage, 1988, woman aged 34-46", span)
subtitle(" ")
note("Source: 1988 data from NLS, U.S. Dept of Labor,
Bureau of Labor Statistics", span){txt}
{it:({stata "gr_example2 grbox2":click to run})}
{* graph grbox2}{...}
{marker remarks2}{...}
{title:Examples of syntax}
{pstd}
Below we show you some {cmd:graph} {cmd:box} commands and tell you what each
would do:
{p 4 8 8}
{cmd:graph box bp}{break}
One big box showing statistics on blood pressure.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -