⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 marker_label_options.hlp

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 HLP
📖 第 1 页 / 共 2 页
字号:
	     {c LT}{hline 21}{c -}{hline 6}{c -}{hline 7}{c RT}
	 50. {c |} {res}              Haiti     54     410 {txt}{c |}
	 51. {c |} {res}           Honduras     69     740 {txt}{c |}
	 52. {c |} {res}            Jamaica     75    1740 {txt}{c |}
	 53. {c |} {res}             Mexico     72    3840 {txt}{c |}
	 54. {c |} {res}          Nicaragua     68    1896 {txt}{c |}
	     {c LT}{hline 21}{c -}{hline 6}{c -}{hline 7}{c RT}
	 55. {c |} {res}             Panama     74    2990 {txt}{c |}
	 56. {c |} {res}        Puerto Rico     76       . {txt}{c |}
	 57. {c |} {res}Trinidad and Tobago     73    4520 {txt}{c |}
	 58. {c |} {res}      United States     77   29240 {txt}{c |}
	     {c BLC}{hline 21}{c -}{hline 6}{c -}{hline 7}{c BRC}{txt}

{pstd}
We might graph these data and use labels to indicate the country by typing

{phang2}
	{cmd:. scatter lexp gnppc if region==2, mlabel(country)}
{p_end}
	  {it:({stata "gr_example lifeexp: scatter lexp gnppc if region==2, mlabel(country)":click to run})}
{* graph mlab1}{...}


{marker remarks2}{...}
{title:Eliminating overprinting and overruns}

{pstd}
Note that in the graph, the label "United States" runs off the right edge and
the labels for Honduras and El Salvador are overprinted.  Problems like
that invariably occur when using marker labels.  The {cmd:mlabposition()}
allows specifying where the labels appear, and we might try

{phang2}
	{cmd:. scatter lexp gnppc if region==2, mlabel(country) mlabpos(9)}

{pstd}
to move the labels to the 9 o'clock position, meaning to the
left of the point.  In this case, however, that will introduce more problems
than it will solve.  You could try other clock positions around the point,
but we could not find one that was satisfactory.

{pstd}
If our only problem were with "United States" running off the right, an
adequate solution might be to widen the {it:x} axis so that there would be
room for the label "United States" to fit:

	{cmd:. scatter lexp gnppc if region==2, mlabel(country)}
				{cmd:xscale(range(35000))}
	  {it:({stata "gr_example lifeexp: scatter lexp gnppc if region==2, mlabel(country) xscale(range(35000))":click to run})}
{* graph mlab2}{...}

{pstd}
That would solve one problem but will leave us with the overprinting problem.
The way to solve that problem is to move the Honduras label to being to the
left of its point, and the way to do that is to specify the option
{cmd:mlabvposition(}{it:varname}{cmd:)} rather than
{cmd:mlabposition(}{it:clockposstyle}{cmd:)}.  We will create new variable {cmd:pos}
stating where we want each label:

	{cmd}. generate pos = 3

	. replace pos = 9 if country=="Honduras"

	. scatter lexp gnppc if region==2, mlabel(country) mlabv(pos)
				xscale(range(35000)){txt}
	  {it:({stata "gr_example2 markerlabel1":click to run})}
{* graph markerlabel1}{...}

{pstd}
We are near a solution:  Honduras is running off the left edge of
the graph, but we know how to fix that.  You may be tempted to solve this
problem just as we solved the problem with the United States label:  expand
the range, say to {cmd:range(-500 35000)}.  That would be a fine solution.

{pstd}
In this case, however, we will increase the margin between the left edge of
the plot area and the {it:y} axis by adding the option
{cmd:plotregion(margin(l+9))}; see {it:{help region_options}}.
{cmd:plotregion(margin(l+9))} says to increase the margin on the left by 9
percent, and this is really the "right" way to handle margin problems:{cmd}

	. scatter lexp gnppc if region==2, mlabel(country) mlabv(pos)
				xscale(range(35000))
				plotregion(margin(l+9)){txt}
	  {it:({stata "gr_example2 markerlabel2":click to run})}{txt}
{* graph markerlabel2}{...}

{pstd}
The overall result is adequate.  Were we producing this graph for publication,
we would move the label for United States to the left of its point, just as
we did with Honduras, rather than widening the {it:x} axis.


{marker remarks3}{...}
{title:Advanced use}

{pstd}
Let us now consider properly graphing the life-expectancy data and graphing
more of it.  This time, we will include South America, as well as North and
Central America and we will graph the data on a log(GNP) scale.


	{cmd}. sysuse lifeexp, clear
	. keep if region==2 | region==3{...}
{col 70}{txt}{it:(note 1)}{cmd}

	. replace gnppc = gnppc / 1000
	. label var gnppc "GNP per capita (thousands of dollars)"{...}
{col 70}{txt}{it:(note 2)}{cmd}

	. generate lgnp = log(gnp)
	. qui reg lexp lgnp
	. predict hat
	. label var hat "Linear prediction"{...}
{col 70}{txt}{it:(note 3)}{cmd}

	. replace country = "Trinidad" if country=="Trinidad and Tobago"
	. replace country = "Para" if country == "Paraguay"{...}
{col 70}{txt}{it:(note 4)}{cmd}

	. generate pos = 3
	. replace pos = 9 if lexp > hat{...}
{col 70}{txt}{it:(note 5)}{cmd}

	. replace pos = 3 if country == "Colombia"
	. replace pos = 3 if country == "Para"
	. replace pos = 3 if country == "Trinidad"
	. replace pos = 9 if country == "United States"{...}
{col 70}{txt}{it:(note 6)}{cmd}

	. twoway (scatter lexp gnppc, mlabel(country) mlabv(pos))
		 (line hat gnppc, sort)
		 , xscale(log) xlabel(.5 5 10 15 20 25 30, grid)
		   legend(off)
		   title("Life expectancy vs. GNP per capita")
		   subtitle("North, Central, and South America")
		   note("Data source:  World bank, 1998")
		   ytitle("Life expectancy at birth (years)"){txt}
	  {it:({stata "gr_example2 markerlabel3":click to run})}{txt}
{* graph markerlabel3}{...}

{pstd}
Notes:

{phang2}
1.  In these data, region 2 is North and Central America, and region 3 is
    South America.

{phang2}
2.  We divide gnppc by 1,000 to keep the {it:x} axis labels from running
    into each other.

{phang2}
3.  We add a linear regression prediction.  We cannot use {cmd:graph}
    {cmd:twoway} {cmd:lfit} because we want the predictions
    based on a regression of log(GNP), not GNP.

{phang2}
4.  The first time we graphed the results, we discovered that there was
    no way we could make the names of these two countries fit on our
    graph, so we shortened them.

{phang2}
5.  We are going to place the marker labels to the left of the marker
    when life expectancy is above the regression line and to the right
    of the marker otherwise.

{phang2}
6.  To keep labels from overprinting, we need to override rule (5) for a few
countries.

{pstd}
Also see {it:{help scale_option}} for another rendition of this graph.
In that rendition, we specify one more
option{hline 2}{cmd:scale(1.1)}{hline 2}
to increase the size of the text and markers by 10%.


{marker remarks4}{...}
{title:Using marker labels in place of markers}

{pstd}
In addition to specifying where the marker label goes relative to the marker,
you can specify that the marker label be used instead of the marker.
{cmd:mlabposition(0)} means that the label is to be centered
where the marker would appear.  To suppress the display of the marker as
well, specify option {cmd:msymbol(i)}; see {it:{help marker_options}}.

{pstd}
Using the labels in place of the points tends to work well in analysis graphs
where our interest is often in identifying the outliers.  Below we graph the
entire {cmd:lifeexp.dta} data:

{phang2}
	{cmd:. scatter lexp gnppc, xscale(log) mlab(country) m(i)}
{p_end}
	  {it:({stata "gr_example lifeexp: scatter lexp gnppc, xscale(log) mlab(country) m(i)":click to run})}
{* graph mlab3}{...}

{pstd}
In the above graph, we also specified {cmd:xscale(log)} to convert the {it:x}
axis to a log scale.  A log {it:x} scale is more appropriate for these
data, but had we used it earlier, the overprinting problem with
Honduras and El Salvador would have disappeared, and we wanted to show
how to handle the problem.


{title:Also see}

{psee}
Manual:  {bf:[G] {it:marker_label_options}}

{psee}
Online:  {helpb scatter};
{it:{help markerlabelstyle}},
{it:{help clockposstyle}},
{it:{help relativesize}},
{it:{help anglestyle}},
{it:{help textstyle}},
{it:{help textsizestyle}},
{it:{help colorstyle}},
{p_end}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -