📄 addplot_option.hlp
字号:
{smcl}
{* 04mar2005}{...}
{cmd:help addplot_option}
{hline}
{* index addplot() tt option}{...}
{title:Title}
{p2colset 5 27 29 2}{...}
{p2col :{hi:[G] {it:addplot_option}} {hline 2}}Option for adding additional twoway plots to command{p_end}
{p2colreset}{...}
{title:Syntax}
{p 8 16 2}
{it:command}
...
[{cmd:,}
...
{cmd:addplot(}{it:plot} ... [{cmd:||} {it:plot} ... [...]]{cmd:)}
...]
{phang}
where {it:plot} may be
any subcommand of {cmd:graph} {cmd:twoway},
such as
{cmd:scatter},
{cmd:line}, {cmd:histogram}, etc.
{title:Description}
{pstd}
Some commands that draw graphs (but do not start with the word {cmd:graph})
are documented in the other reference manuals. Many of those commands allow
the {cmd:addplot()} option. This option allows them to overlay their results
on top of {cmd:graph} {cmd:twoway} plots.
{title:Option}
{phang}
{cmd:addplot(}{it:plot}{cmd:)}
specifies the rest of the {cmd:graph} {cmd:twoway} subcommands to be
added to the {cmd:graph} {cmd:twoway} command issued by {it:command}.
{title:Remarks}
{pstd}
Remarks are presented under the headings
{help addplot_option##remarks1:Commands that allow the addplot() option}
{help addplot_option##remarks2:Advantage of graph twoway commands}
{help addplot_option##remarks3:Advantages of graphic commands implemented outside of graph twoway}
{help addplot_option##remarks4:Use of the addplot() option}
{marker remarks1}{...}
{title:Commands that allow the addplot() option}
{pstd}
{cmd:graph} commands never allow the {cmd:addplot()} option. The
{cmd:addplot()} option is allowed by commands outside of {cmd:graph} that are
implemented in terms of {cmd:graph} {cmd:twoway}.
{pstd}
For instance, the {cmd:histogram} command{hline 2}see
{helpb histogram}{hline 2}allows {cmd:addplot()}. {cmd:graph} {cmd:twoway}
{cmd:histogram}{hline 2}see {helpb twoway histogram}{hline 2}does not.
{marker remarks2}{...}
{title:Advantage of graph twoway commands}
{pstd}
The advantage of {cmd:graph} {cmd:twoway} commands is that they can be
overlaid, one on top of the other. For instance, you can type
{phang2}
{cmd:. graph twoway scatter} {it:yvar} {it:xvar} {cmd:||}
{cmd:lfit} {it:yvar} {it:xvar}
{pstd}
and the separate graphs produced, {cmd:scatter} and {cmd:lfit}, are
combined into one.
The variables to which each refers need not even be the same:
{phang2}
{cmd:. graph twoway scatter} {it:yvar} {it:xvar} {cmd:||}
{cmd:lfit} {it:y2var} {it:x2var}
{marker remarks3}{...}
{title:Advantages of graphic commands implemented outside of graph twoway}
{pstd}
Graphic commands implemented outside of {cmd:graph} {cmd:twoway} can
have simpler syntax. For instance, the {cmd:histogram} command
has an option, {cmd:normal}, that will overlay a normal curve on top of
the histogram:
{cmd:. histogram} {it:myvar}{cmd:, normal}
{pstd}
That is easier than typing
{cmd:. summarize} {it:myvar}
{cmd:. graph twoway histogram} {it:myvar} {cmd:||}
{cmd:function} {cmd:normden(x,`r(mean)',`r(sd)'),} {cmd:range(}{it:myvar}{cmd:)}
{pstd}
which is the {cmd:graph} {cmd:twoway} way of producing the same thing.
{pstd}
Thus the trade-off between {cmd:graph} and non-{cmd:graph} commands is one of
greater flexibility versus easier use.
{marker remarks4}{...}
{title:Use of the addplot() option}
{pstd}
The {cmd:addplot()} option attempts to give back flexibility to non-{cmd:graph}
graphic commands. Such commands are, in fact, implemented in terms of
{cmd:graph} {cmd:twoway}. For instance, when you type
{cmd:. histogram} ...
{pstd}
or you type
{cmd:. sts graph} ...
{pstd}
the result is that those commands construct a complicated
{cmd:graph} {cmd:twoway} command
{cmd:-> graph twoway} {it:something_complicated}
{pstd}
and then run that for you. When you specify the addplot option, such as
{cmd:. histogram} ...{cmd:, addplot(}{it:your_contribution}{cmd:)}
{pstd}
or
{cmd:. sts graph, addplot(}{it:your_contribution}{cmd:)}
{pstd}
the result is that the commands construct
{phang2}
{cmd:-> graph twoway} {it:something_complicated} {cmd:||}
{it:your_contribution}
{pstd}
Let us assume that you have survival data and wish to visually compare the
Kaplan-Meier (i.e., the empirical survivor function) to the function that
would be predicted if the survival times were assumed to be exponentially
distributed. Simply typing
{cmd:. sysuse cancer, clear}
{cmd:. quietly stset studytime, fail(died)}
{cmd:. sts graph}
{it:({stata "gr_example2 plotop1":click to run})}
{* graph plotop1}{...}
{pstd}
will obtain a graph of the empirical estimate.
To obtain the exponential estimate, you might type
{cmd:. quietly streg, distribution(exponential)}
{cmd:. predict S, surv}
{cmd:. graph twoway line S _t, sort}
{it:({stata "gr_example2 plotop2":click to run})}
{* graph plotop2}{...}
{pstd}
To put these two graphs together, you can type
{cmd:. sts graph, addplot(line S _t, sort)}
{it:({stata "gr_example2 plotop3":click to run})}
{* graph plotop3}{...}
{pstd}
The result is just as if you typed
{cmd:. sts graph || line S _t, sort}
{pstd}
if only that were allowed.
{title:Also see}
{psee}
Manual: {bf:[G] {it:addplot_option}}
{psee}
Online: {helpb twoway}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -