📄 added_text_options.hlp
字号:
{smcl}
{* 07mar2005}{...}
{cmd:help added_text_options}
{hline}
{* index text() tt option}{...}
{* index ttext() tt option}{...}
{title:Title}
{p2colset 5 30 32 2}{...}
{p2col :{hi:[G] {it:added_text_option}} {hline 2}}Option for adding text to twoway graphs{p_end}
{p2colreset}{...}
{title:Syntax}
{it:added_text_options}{col 37}description
{hline 70}
{cmd:text(}{it:text_arg}{cmd:)}{...}
{col 37}add text at specified {it:y} {it:x}
{cmd:ttext(}{it:text_arg}{cmd:)}{...}
{col 37}add text at specified {it:y} {it:t}
{hline 70}
{pin}
The above options are {it:merged-implicit}; see {help repeated options}.
{pstd}
where {it:text_arg} is
{it:loc_and_text} [{it:loc_and_text} ...] [{cmd:,} {it:textoptions}]
{pstd}
and where {it:loc_and_text} is
{it:#_y} {it:#_x} {cmd:"}{it:text}{cmd:"} [{cmd:"}{it:text}{cmd:"} ...]
{it:textoptions}{col 37}description
{hline 70}
{cmdab:yax:is:(}{it:#}{cmd:)}{...}
{col 37}how to interpret {it:#_y}
{cmdab:xax:is:(}{it:#}{cmd:)}{...}
{col 37}how to interpret {it:#_x}
{cmdab:place:ment:(}{it:{help compassdirstyle}}{cmd:)}{...}
{col 37}where to locate relative to {it:#_y} {it:#_x}
{it:{help textbox_options}}{...}
{col 37}look of text
{hline 70}
{pin}
Note that {cmd:placement()} is also a textbox option, but ignore the
description of {cmd:placement()} found there in favor of the one below.
{title:Description}
{pstd}
{cmd:text()} adds the specified text to the specified location in the plot
region.
{pstd}
{cmd:ttext()} is an extension to {cmd:text()}, accepting a date in place of
{it:#_x} when the time axis has a time format; see {help datelist}.
{title:Options}
{phang}
{cmd:text()} and {cmd:ttext()}
specify the location and text to be displayed.
{title:Suboptions}
{phang}
{cmd:yaxis(}{it:#}{cmd:)}
and
{cmd:xaxis(}{it:#}{cmd:)}
specify how {it:#_y} and {it:#_x} are to be interpreted when
there are multiple {it:y} and {it:x} (or {it:t}) axis scales; see
{it:{help axis_choice_options}}.
{pmore}
In the usual case, there is one {it:y} axis and one {it:x} axis,
so options {cmd:yaxis()} and {cmd:xaxis()} are not specified.
{it:#_y} is specified in units of the {it:y} scale and {it:#_x} in
units of the {it:x} scale.
{pmore}
In the multiple-axis case, specify {cmd:yaxis(}{it:#}{cmd:)} and/or
{cmd:xaxis(}{it:#}{cmd:)} to specify which units you wish to use.
{cmd:yaxis(1)} and {cmd:xaxis(1)} are the defaults.
{phang}
{cmd:placement(}{it:compassdirstyle}{cmd:)} specifies where the textbox
is to be displayed relative to {it:#_y} {it:#_x}.
The default is usually {cmd:placement(center)}. The default is
controlled both by the scheme and by the {it:textbox_option}
{cmd:tstyle(}{it:textboxstyle}{cmd:)}; see {help schemes} and
{it:{help textbox_options}}.
The available choices are
{cmd:placement()} location of text
{hline 64}
{cmd:c} centered on the point, vertically and horizontally
{cmd:n} above the point, centered
{cmd:ne} upper-right corner on the point
{cmd:e} right of the point, vertically centered
{cmd:se} lower-right corner on the point
{cmd:s} below point, centered
{cmd:sw} lower-left corner on the point
{cmd:w} left of the point, vertically centered
{cmd:nw} upper-left corner on the point
{hline 64}
{it:north northwest northeast}
{it:west} X {it:east} X
{it:south southwest southeast}
{pmore}
You can see {it:{help compassdirstyle}}, but that will just give
you synonyms for {cmd:c}, {cmd:n}, {cmd:ne}, ..., {cmd:nw}.
{phang}
{it:textbox_options}
specifies the look of the text; see {it:{help textbox_options}}.
{title:Remarks}
{pstd}
Remarks are presented under the headings
{help added_text_options##remarks1:Typical use}
{help added_text_options##remarks2:Advanced use}
{help added_text_options##remarks3:Use of the textbox option width()}
{marker remarks1}{...}
{title:Typical use}
{pstd}
{cmd:text()} is used for placing annotations on graphs. One example is the
labeling of outliers. For instance, type
{cmd:. sysuse auto, clear}
{cmd:. twoway qfitci mpg weight, stdf || scatter mpg weight}
{it:(graph omitted)}
{pstd}
Notice that there are four outliers. First, we find the outliers by typing
{cmd:. quietly regress mpg weight}
{cmd:. predict hat}
{cmd:. predict s, stdf}
{cmd:. generate upper = hat + 1.96*s}
{cmd:. list make mpg weight if mpg>upper}
{txt}
{c TLC}{hline 13}{c -}{hline 5}{c -}{hline 8}{c TRC}
{c |} {res}make mpg weight {txt}{c |}
{c LT}{hline 13}{c -}{hline 5}{c -}{hline 8}{c RT}
42. {c |} {res}Plym. Arrow 28 3,260 {txt}{c |}
57. {c |} {res}Datsun 210 35 2,020 {txt}{c |}
66. {c |} {res}Subaru 35 2,050 {txt}{c |}
71. {c |} {res}VW Diesel 41 2,040 {txt}{c |}
{c BLC}{hline 13}{c -}{hline 5}{c -}{hline 8}{c BRC}{txt}
{pstd}
Now we can remake the graph and label the outliers:
{cmd}. twoway qfitci mpg weight, stdf ||
scatter mpg weight, ms(O)
text(41 2040 "VW Diesel", place(e))
text(28 3260 "Plymouth Arrow", place(e))
text(35 2050 "Datsun 210 and Subaru", place(e)){txt}
{it:({stata `"gr_example auto: twoway qfitci mpg weight, stdf || scatter mpg weight, ms(O) text(41 2040 "VW Diesel", place(e)) text(28 3260 "Plymouth Arrow", place(e)) text(35 2050 "Datsun 210 and Subaru", place(e))"':click to run})}
{* graph atofig1}{...}
{marker remarks2}{...}
{title:Advanced use}
{pstd}
Another common use of {it:text} is to add an explanatory box of text inside
the graph:
{cmd}. sysuse uslifeexp, clear
. twoway line le year ||
fpfit le year ||
, ytitle("Life Expectancy, years")
xlabel(1900 1918 1940(20)2000)
title("Life Expectancy at Birth")
subtitle("U.S., 1900-1999")
note("Source: National Vital Statistics Report, Vol. 50 No. 6")
legend(off)
text( 48.5 1923
"The 1918 Influenza Pandemic was the worst epidemic"
"known in the U.S."
"More citizens died than in all combat deaths of the"
"20th century."
, place(se) box just(left) margin(l+4 t+1 b+1) width(85) ){txt}
{it:({stata "gr_example2 textop1":click to run})}
{* graph textop1}{...}
{pstd}
The only thing to note in the above command is the {cmd:text()} option:
{cmd}text( 48.5 1923
"The 1918 Influenza Pandemic was the worst epidemic"
"known in the U.S."
"More citizens died than in all combat deaths of the"
"20th century."
, place(se) box just(left) margin(l+4 t+1 b+1) width(85) ){txt}
{pstd}
and, in particular, we want to draw your eye to the location of the text
and the suboptions:
{cmd}text( 48.5 1923
{txt}...{cmd}
, place(se) box just(left) margin(l+4 t+1 b+1) width(85) ){txt}
{pstd}
We placed the text at {it:y}=48.5, {it:x}=1923, {cmd:place(se)}, meaning the
lower-right corner of the box was located at {it:y}=48.5, {it:x}=1923.
{pstd}
The other suboptions, {cmd:box} {cmd:just(left)} {cmd:margin(l+4} {cmd:t+1}
{cmd:b+1)} {cmd:width(85)}, are {it:textbox_options}. We specified {cmd:box}
to draw a border around the textbox, and we specified
{cmd:just(left)}{hline 2}an abbreviation for
{cmd:justification(left)}{hline 2}so that the text was left-justified inside
the box.
{pstd}
{cmd:margin(l+4} {cmd:t+1} {cmd:b+1)} made the text in the box look better.
On the left we added 4%, and on the top and bottom we added 1%; see
{it:{help textbox_options}} and {it:{help relativesize}}.
{pstd}
{cmd:width(85)} was specified to solve the problem described below.
{* index width() tt textbox option}{...}
{* index height() tt textbox option}{...}
{* index borders, misplacement of}{...}
{* index text, running outside of borders}{...}
{marker remarks3}{...}
{title:Use of the textbox option width()}
{pstd}
Let us look at the results of the above command, omitting the {cmd:width()}
suboption. What you would see on your screen{hline 2}or in a
printout{hline 2}might look virtually identical to the version we just drew,
or it might look like this
{it:({stata "gr_example2 textop2":click to run})}
{* graph textop2}{...}
{pstd}
or like this:
{it:({stata "gr_example2 textop3":click to run})}
{* graph textop3}{...}
{pstd}
That is, Stata might make the textbox too narrow or too wide. In the above
illustrations, we have exaggerated the extent of the problem, but it is not
uncommon for the box to run a little narrow or a little wide. Moreover, with
respect to this one problem, how the graph appears on your screen is no
guarantee as to how it will appear when printed.
{pstd}
This problem arises because Stata uses an approximation formula to determine
the width of the text. This approximation is good for some fonts and poorer
for others.
{pstd}
When the problem arises, use
the {it:textbox_option}
{cmd:width(}{it:relativesize}{cmd:)} to work
around it. {cmd:width()} overrides Stata's
calculation. In fact, we drew the two examples above by purposely misstating
the {cmd:width()}. In the first case, we specified {cmd:width(40)}, and in the
second, {cmd:width(95)}.
{pstd}
Getting the {cmd:width()} right is a matter of trial and error. The correct
width will nearly always be between 0 and 100.
{pstd}
Corresponding to {cmd:width(}{it:relativesize}{cmd:)}, there is also the
{it:textbox_option} {cmd:height(}{it:relativesize}{cmd:)}, but Stata never
gets the height incorrect.
{title:Also see}
{psee}
Manual: {bf:[G] {it:added_text_option}}
{psee}
Online: {it:{help textbox_options}};
{it:{help datelist}}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -