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

📄 scatter.hlp

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 HLP
📖 第 1 页 / 共 3 页
字号:
beside the marker symbol{hline 2}or in place of it{hline 2}to identify the
points.  See {it:{help marker_label_options}}.


{marker remarks14}{...}
{title:Weighted markers}

{pstd}
If weights are specified{hline 2}see {help weight}{hline 2}the size of the
marker is scaled according to the size of the weights.  {cmd:aweight}s,
{cmd:fweight}s, and {cmd:pweight}s are allowed and all are treated the same;
{cmd:iweight}s are not allowed because {cmd:scatter} would not know what to do
with negative values.  Weights affect the size of the marker and nothing else
about the plot.

{pstd}
Below we use U.S. state-averaged data to graph the divorce rate in a
state versus the state's median age.  We scale the symbols to be proportional
to the population size:

	{cmd:. sysuse census, clear}

	{cmd:. generate drate = divorce / pop18p}

	{cmd:. label var drate "Divorce rate"}

	{cmd:. scatter drate medage [w=pop18p] if state!="Nevada", msymbol(Oh)}
	     {cmd:note("Stata data excluding Nevada"}
	     {cmd:"Area of symbol proportional to state's population aged 18+")}
	  {it:({stata gr_example2 scatterwgt:click to run})}
{* graph scatterwgt}{...}

{pstd}
Note the use of the {cmd:msymbol(Oh)} option.  Hollow scaled markers look
much better than solid ones.

{pstd}
{cmd:scatter} scales the symbols so that the sizes are a fair representation
when the weights represent population weights.  To wit:  If all the weights
except one are 1,000 and the exception is 999, the symbols will all be of
almost equal size.  The weight 999 observation will not be a dot and the
weight 1,000 observation giant circles as would be the result if the
exception had weight 1.

{pstd}
When weights are specified, option {cmd:msize()} (which also affects the
size of the marker), if specified, is ignored.

{pstd}
Weights are ignored when the {cmd:mlabel()} option is specified.


{marker jitter}{...}
{marker remarks15}{...}
{title:Jittered markers}

{pstd}
{cmd:scatter} will add spherical random noise to your data before plotting if
you specify {cmd:jitter(}{it:#}{cmd:)}, where {it:#} represents the size of
the noise as a percentage of the graphical area.  This can be useful for
creating graphs of categorical data when, were the data not jittered, many of
the points would be on top of each other, making it impossible to tell whether
the plotted point represented one or 1,000 observations.

{pstd}
For instance, in a variation on auto.dta used below, mpg is recorded in units
of 5 mpg, and weight is recorded in units of 500 pounds.  A standard scatter
has considerable overprinting:

	{cmd:. sysuse autornd, clear}

	{cmd:. scatter mpg weight}
	  {it:({stata "gr_example autornd: scatter mpg weight":click to run})}
{* graph scatter8}{...}

{pstd}
There are 74 points in the graph, even though it appears because of
overprinting as if there are only 19.  Jittering solves that problem:

	{cmd:. scatter mpg weight, jitter(7)}
	  {it:({stata "gr_example autornd: scatter mpg weight, jitter(7)":click to run})}
{* graph scatter9}{...}


{marker remarks16}{...}
{title:Connected lines}

{pstd}
The {cmd:connect()} option allows you to connect the points of a graph.  The
default is not to connect the points.

{pstd}
If you want connected points, you probably want to specify {cmd:connect(l)},
which is usually abbreviated {cmd:c(l)}.  The {cmd:l} means that the points
are to be connected with straight lines.  Points can be connected in other 
ways (such as a stairstep fashion), but usually {cmd:c(l)} is the right
choice.  The command

	{cmd:. scatter} {it:yvar} {it:xvar}{cmd:, c(l)}

{pstd}
will plot {it:yvar} versus {it:xvar}, marking the points in the usual
way, and drawing straight lines between the points.  It is common also to
specify the {cmd:sort} option,

{phang2}
	{cmd:. scatter} {it:yvar} {it:xvar}{cmd:, c(l) sort}

{pstd}
because otherwise points are connected in the order of the data.  If the data
are already in the order of {it:xvar}, the {cmd:sort} is unnecessary.
You can also omit the {cmd:sort} when creating special effects.

{pstd}
{cmd:connect()} is often specified with the {cmd:msymbol(i)} option to
suppress the display of the individual points:

{phang2}
	{cmd:. scatter} {it:yvar} {it:xvar}{cmd:, c(l) sort m(i)}

{pstd}
See {it:{help connect_options}}.


{marker remarks17}{...}
{title:Graphs by groups}

{pstd}
Option {cmd:by()} specifies that graphs are to be drawn separately for each of
the different groups and the results arrayed into a single display.
Below we use country data and group the results by region of the world:

	{cmd:. sysuse lifeexp, clear}

	{cmd:. scatter lexp gnppc, by(region)}
	  {it:({stata "gr_example lifeexp: scatter lexp gnppc, by(region)":click to run})}
{* graph scatter10}{...}

{pstd}
Variable {cmd:region} is a numeric variable taking on values 1, 2, and 3.
Separate graphs were drawn for each value of region.  The graphs were titled
"Eur & C. Asia", "N.A.", and "S.A."  because numeric variable {cmd:region} had
been assigned a value label, but results would have been the same had variable
{cmd:region} been a string directly containing "Eur & C. Asia", "N.A.", and
"S.A.".

{pstd}
See 
{it:{help by_option}} for more information on this useful option.


{marker remarks18}{...}
{title:Saving graphs}

{pstd}
To save a graph to disk for later printing or reviewing, include the
{cmd:saving()} option,

{phang2}
	{cmd:. scatter} ...{cmd:,} ... {cmd:saving(}{it:filename}{cmd:)}

{pstd}
or use the {cmd:graph} {cmd:save} command afterwards:

	{cmd:. scatter} ...
	{cmd:. graph save} {it:filename}

{pstd}
See {it:{help saving_option}} and {helpb graph save}.  Also
see {help gph files} for information on how files such as
{it:filename}{cmd:.gph} can be put to subsequent use.


{marker remarks19}{...}
{title:Appendix:  Styles and composite styles}

{pstd}
Many options end in the word style, including, to name a
few, {cmd:mstyle()}, {cmd:mlabstyle()}, and {cmd:lstyle()}.  Option
{cmd:mstyle()}, for instance, is described as setting the "overall look" of
a marker.  What does that mean?

{pstd}
How something looks{hline 2}a marker, a marker label, a line{hline 2}is
specified by lots of detail options.  In the case of markers, option
{cmd:msymbol()} specifies its shape, {cmd:mcolor()} specifies its color,
{cmd:msize()} specifies its size, and so on.

{pstd}
A {it:style} specifies a composite of related option settings.  If you typed
option {cmd:mstyle(p1)}, you would be specifying a whole set of values for
{cmd:msymbol()}, {cmd:mcolor()}, {cmd:msize()} and all the other {cmd:m*()}
options.  {cmd:p1} is called the name of a style, and {cmd:p1} contains the
settings.

{pstd}
Concerning {cmd:mstyle()}, and all the other options ending in the word style,
throughout this manual you will read statements such as

{pmore}
    Option {it:whatever}{cmd:style()} specifies the overall look of
    {it:whatever}, such as its {it:(insert list here)}.  The other options
    allow you to change the attributes of a {it:whatever}, but
    {it:whatever}{cmd:style()} is the starting point.

{pmore}
     You need not specify {it:whatever}{cmd:style()} just because there is
     something you want to change about the look of a {it:whatever}, and in
     fact, most people seldom specify the {it:whatever}{cmd:style()} option.
     You specify {it:whatever}{cmd:style()} when another style exists that is
     exactly what you desire or when another style would allow you to specify
     fewer changes to obtain what you want.

{pstd}
Styles actually come in two flavors called {it:composite styles} and
{it:detail} {it:styles}, and the above statement applies only to composite
styles and appears only in manual entries concerning composite styles.
Composite styles are specified in options that end in the word style.  The
following are examples of composite styles:

	{cmd:mstyle(}{it:symbolstyle}{cmd:)}
	{cmd:mlstyle(}{it:linestyle}{cmd:)}
	{cmd:mlabstyle(}{it:markerlabelstyle}{cmd:)}
	{cmd:lstyle(}{it:linestyle}{cmd:)}
	{cmd:pstyle(}{it:pstyle}{cmd:)}

{pstd}
The following are examples of detail styles:

	{cmd:mcolor(}{it:colorstyle}{cmd:)}
	{cmd:mlwidth(}{it:linewidthstyle}{cmd:)}
	{cmd:mlabsize(}{it:textsizestyle}{cmd:)}
	{cmd:lpattern(}{it:linepatternstyle}{cmd:)}

{pstd}
In the above examples, distinguish carefully between option names such as
{cmd:mcolor()} and option arguments such as {it:colorstyle}.  {it:colorstyle}
is an example of a detail style because it appears in the option
{cmd:mcolor()}, and the option name does not end in the word style.

{pstd}
Detail styles specify precisely how an attribute of something looks, and
composite styles specify an "overall look" in terms of detail-style values.

{pstd}
Composite styles sometimes contain other composite styles as members.  For
instance, when you specify the {cmd:mstyle()} option{hline 2}which specifies
the overall look of markers{hline 2}you are also specifying an
{cmd:mlstyle()}{hline 2}which specifies the overall look of the lines that
outline the shape of the markers.  That does not mean you cannot specify the
{cmd:mlstyle()} option, too.  It just means that specifying {cmd:mstyle()}
implies an {cmd:mlstyle()}.  The order in which you specify the options does
not matter.  You can type

{phang2}
	{cmd:. scatter} ...{cmd:,} ... {cmd:mstyle(}...{cmd:)} ... {cmd:mlstyle(}...{cmd:)} ...

{pstd}
or

{phang2}
	{cmd:. scatter} ...{cmd:,} ... {cmd:mlstyle(}...{cmd:)} ... {cmd:mstyle(}...{cmd:)} ...

{pstd}
and, either way, {cmd:mstyle()} will be set as you specify, and then
{cmd:mlstyle()} will be reset as you wish.  The same applies for mixing
composite-style and detail-style options.  Option {cmd:mstyle()} implies an
{cmd:mcolor()} value.  Even so, you may type

{phang2}
	{cmd:. scatter} ...{cmd:,} ... {cmd:mstyle(}...{cmd:)} ... {cmd:mcolor(}...{cmd:)} ...

{pstd}
or

{phang2}
	{cmd:. scatter} ...{cmd:,} ... {cmd:mcolor(}...{cmd:)} ... {cmd:mstyle(}...{cmd:)} ...

{pstd}
and the outcome will be the same.

{pstd}
The grandest composite style of them all is {cmd:pstyle(}{it:pstyle}{cmd:)}.
It contains all the other composite styles and {cmd:scatter} ({cmd:twoway},
in fact) makes great use of this grand style.
When you type

{phang2}
	{cmd:. scatter} {it:y1var} {it:y2var} {it:xvar}{cmd:,} ...

{pstd}
results are as if you typed

{phang2}
	{cmd:. scatter} {it:y1var} {it:y2var} {it:xvar}{cmd:,} {cmd:pstyle(p1 p2)} ...

{pstd}
That is, {it:y1var} versus {it:xvar} is plotted using {cmd:pstyle(p1)}, and
{it:y2var} versus {it:xvar} is plotted using {cmd:pstyle(p2)}.
It is the {cmd:pstyle(p1)} that sets all the defaults{hline 2} which marker
symbols are used, what color they are, etc.

{pstd}
The same applies if you type

{phang2}
	{cmd:. scatter} {it:y1var} {it:xvar}{cmd:,} ... {cmd:||}
		{cmd:scatter} {it:y2var} {it:xvar}{cmd:,} ...

{pstd}
{it:y1var} versus {it:xvar} is plotted using {cmd:pstyle(p1)}, and
{it:y2var} versus {it:xvar} is plotted using {cmd:pstyle(p2)}, just as if
you had typed

{phang2}
	{cmd:. scatter} {it:y1var} {it:xvar}{cmd:,} {cmd:pstyle(p1)} ... {cmd:||}
		{cmd:scatter} {it:y2var} {it:xvar}{cmd:,} {cmd:pstyle(p2)} ...

{pstd}
The same applies if you mix {cmd:scatter} with other plottypes:

{phang2}
	{cmd:. scatter} {it:y1var} {it:xvar}{cmd:,} ... {cmd:||}
		{cmd:line} {it:y2var} {it:xvar}{cmd:,} ...

{pstd}
is equivalent to

{phang2}
	{cmd:. scatter} {it:y1var} {it:xvar}{cmd:,} {cmd:pstyle(p1)} ... {cmd:||}
		{cmd:line} {it:y2var} {it:xvar}{cmd:,} {cmd:pstyle(p2)} ...

{pstd}
and,

	{cmd:. twoway (}..., ...{cmd:) (}..., ...{cmd:),} ...

{pstd}
is equivalent to

{phang2}
	{cmd:. twoway (}..., {cmd:pstyle(p1)} ...{cmd:) (}...{cmd:,} {cmd:pstyle(p2)} ...{cmd:),} ...

{pstd}
which is why we said that it is {cmd:twoway}, and not just {cmd:scatter}, that
exploits {cmd:scheme()}.

{pstd}
You can put this to use.  Pretend that you have a dataset on husbands and
wives and it contains the variables

	{cmd:hinc}        husband's income
	{cmd:winc}        wife's income
	{cmd:hed}         husband's education
	{cmd:wed}         wife's education

{pstd}
You wish to draw a graph of income versus education, drawing no distinctions
between husbands and wives.  You type

	{cmd:. scatter hinc hed || scatter winc wed}

{pstd}
You intend to treat husbands and wives the same in the graph, but in the
above example, they are treated differently because {cmd:msymbol(O)} will be
used to mark the points of {cmd:hinc} versus {cmd:hed} and {cmd:msymbol(D)}
will be used to designate {cmd:winc} versus {cmd:wed}.  The color of the
symbols will be different, too.

{pstd}
You could address that problem in many different ways.  You could specify
the {cmd:msymbol()} and {cmd:mcolor()} options, along with whatever other
detail options are necessary to make the two scatters appear the same.
Being knowledgeable, you realize you do not have to do that.  There is,
you know, a composite style that specifies this.  So you get out your
manuals, flip through, and discover that the relevant composite style for
the marker symbols is {cmd:mstyle()}.

{pstd}
Easiest of all, however, would be to remember that {cmd:pstyle()} contains
all the other styles.  Rather than resetting {cmd:mstyle()}, just reset
{cmd:pstyle()}, and whatever needs to be set to make the two plots the same
will be set.  Type

	{cmd:. scatter hinc hed || scatter winc wed, pstyle(p1)}

{pstd}
or, if you prefer,

{phang2}
	{cmd:. scatter hinc hed, pstyle(p1) || scatter winc wed, pstyle(p1)}

{pstd}
You do not need to specify {cmd:pstyle(p1)} for the first plot, however,
because that is the default.

{pstd}
As another example, you have a dataset containing

	{cmd:mpg}         Mileage ratings of cars
	{cmd:weight }     Each car's weight
	{cmd:prediction}  A predicted mileage rating based on weight

{pstd}
You wish to draw the graph

{phang2}
	{cmd:. scatter mpg weight || line prediction weight}

{pstd}
but you wish the appearance of the line to "match" that of the markers used
to plot mpg versus weight.  You could go digging to find out which option
controlled the line style and color and then dig some more to figure
out which line style and color goes with the markers used in the first
plot, but much easier is simply to type

{phang2}
	{cmd:. scatter mpg weight || line prediction weight, pstyle(p1)}


{title:Also see}

{psee}
Manual:  {bf:[G] graph twoway scatter}

{psee}
Online:  {helpb twoway};
{it:{help marker_options}},
{it:{help marker_label_options}},
{it:{help connect_options}},
{it:{help axis_choice_options}},
{it:{help twoway_options}}
{p_end}

⌨️ 快捷键说明

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