📄 line.hlp
字号:
{smcl}
{* 08apr2005}{...}
{cmd:help line} {right:dialogs: {dialog eline:easy line graph}}
{right:{dialog twoway_overlay:overlaid twoway}{space 0}}
{right:{dialog twoway_simple:single twoway}{space 2}}
{hline}
{title:Title}
{p2colset 5 30 32 2}{...}
{p2col :{hi:[G] graph twoway line} {hline 2}}Twoway line plots{p_end}
{p2colreset}{...}
{title:Syntax}
{p 8 24 2}
[{cmdab:tw:oway}]
{cmd:line}
{it:varlist}
{ifin}
[{cmd:,}
{it:options}]
{pstd}
where {it:varlist} is
{it:y_1} [{it:y_2} [...]] {it:x}
{p2colset 9 31 32 2}
{p2col:{it:options}}description{p_end}
{p2line}
INCLUDE help gr_conopt
INCLUDE help gr_axlnk
INCLUDE help gr_twopt
{p2line}
{p 8 8 2}
{it:{help connect_options}} discusses options for a
single {it:y} versus a single {it:x}, see {it:connect_options} in
{bf:{help scatter##connect_options:scatter}} when plotting multiple
{it:y}s against one {it:x}.
{title:Description}
{pstd}
{cmd:line} draws line plots.
{pstd}
{cmd:line} is a command and a {it:plottype} as defined in {helpb twoway}.
Thus the syntax for {cmd:line} is
{cmd:. graph twoway line} ...
{cmd:. twoway line} ...
{cmd:. line} ...
{pstd}
Being a plottype, {cmd:line} may be combined with other plottypes in the
{cmd:twoway} family, as in
{phang2}
{cmd:. twoway (line} ...{cmd:) (scatter} ...{cmd:) (lfit} ...{cmd:)} ...
{pstd}
which can equivalently be written
{phang2}
{cmd:. line} ... {cmd:|| scatter} ... {cmd:|| lfit} ... {cmd:||} ...
{title:Options}
{phang}
{it:options}
are any of the options allowed by the {cmd:graph} {cmd:twoway}
{cmd:scatter} command, except that {it:marker_options},
{it:marker_placement_options}, and {it:marker_label_options} will be
ignored if specified; see {helpb scatter}.
{title:Remarks}
{pstd}
Remarks are presented under the headings
{help line##remarks1:Oneway equivalency of line and scatter}
{help line##remarks2:Typical use}
{help line##remarks3:Advanced use}
{help line##remarks4:Cautions}
{marker remarks1}{...}
{title:Oneway equivalency of line and scatter}
{pstd}
{cmd:line} is similar to {cmd:scatter}, the differences being that by default
the marker symbols are not displayed and the points are connected:
Default {cmd:msymbol()} option: {cmd:msymbol(none ...)}
Default {cmd:connect()} option: {cmd:connect(l ...)}
{pstd}
Thus you get the same results typing
{cmd:. line yvar xvar}
{pstd}
as typing
{phang2}
{cmd:. scatter yvar xvar, msymbol(none) connect(l)}
{pstd}
You can use {cmd:scatter} in place of {cmd:line}, but you may not use
{cmd:line} in place of {cmd:scatter}. Typing
{phang2}
{cmd:. line yvar xvar, msymbol(O) connect(none)}
{pstd}
will not achieve the same results as
{cmd:. scatter yvar xvar}
{pstd}
because {cmd:line}, while it allows you to specify the {it:marker_option}
{cmd:msymbol()}, ignores its setting.
{marker remarks2}{...}
{title:Typical use}
{pstd}
{cmd:line} draws line charts:
{cmd:. sysuse uslifeexp, clear}
{cmd:. line le year}
{it:({stata "gr_example uslifeexp: line le year":click to run})}
{* graph grline1}{...}
{pstd}
Line charts work well with time-series data. With other datasets, lines
are often used to show predicted values and confidence intervals:
{cmd}. sysuse auto, clear
. quietly regress mpg weight
. predict hat
. predict stdf, stdf
. gen lo = hat - 1.96*stdf
. gen hi = hat + 1.96*stdf
{phang2}
. scatter mpg weight || line hat lo hi weight, pstyle(p2 p3 p3) sort{txt}
{p_end}
{it:({stata "gr_example2 line1":click to run})}
{* graph line1}{...}
{pstd}
Do not forget to include the {cmd:sort} option when the data are not in the
order of the {it:x} variable, as they are not above. We also included
{cmd:pstyle(p2 p3 p3)} to give the lower and upper confidence limit lines the
same look; see {help scatter##remarks19:Styles and composite style} under
{hi:Remarks} in {helpb scatter}.
{pstd}
Because {cmd:line} is {cmd:scatter}, we can use any of the options allowed
by {cmd:scatter}. Below we return to the U.S. life-expectancy data
and graph black and white male life expectancies, along with the difference,
specifying lots of options to create an informative and visually pleasing
graph:
{cmd}. sysuse uslifeexp, clear
. gen diff = le_wm - le_bm
. label var diff "Difference"
. line le_wm year, yaxis(1 2) xaxis(1 2)
|| line le_bm year
|| line diff year
|| lfit diff year
||,
ylabel(0(5)20, axis(2) gmin angle(horizontal))
ylabel(0 20(10)80, gmax angle(horizontal))
ytitle("", axis(2))
xlabel(1918, axis(2)) xtitle("", axis(2))
ytitle("Life expectancy at birth (years)")
title("White and black life expectancy")
subtitle("USA, 1900-1999")
note("Source: National Vital Statistics, Vol 50, No. 6"
"(1918 dip caused by 1918 Influenza Pandemic)"){txt}
{it:({stata gr_example2 line2:click to run})}
{* graph line2}{...}
{pstd}
See {helpb scatter}.
{marker remarks3}{...}
{title:Advanced use}
{pstd}
The above graph would look better if we shortened the descriptive text
used in the keys. Below we add
{phang2}
{cmd:legend(label(1 "White males") label(2 "Black males"))}
{pstd}
to our previous command:{cmd}
. line le_wm year, yaxis(1 2) xaxis(1 2)
|| line le_bm year
|| line diff year
|| lfit diff year
||,
ylabel(0(5)20, axis(2) gmin angle(horizontal))
ylabel(0 20(10)80, gmax angle(horizontal))
ytitle("", axis(2))
xlabel(1918, axis(2)) xtitle("", axis(2))
ytitle("Life expectancy at birth (years)")
title("White and black life expectancy")
subtitle("USA, 1900-1999")
note("Source: National Vital Statistics, Vol 50, No. 6"
"(1918 dip caused by 1918 Influenza Pandemic)")
legend(label(1 "White males") label(2 "Black males")){txt}
{it:({stata gr_example2 line3:click to run})}
{pstd}
We might also consider moving the legend to the right of the graph, which
we can do by adding
{cmd:legend(col(1) pos(3))}
{pstd}
resulting in{cmd}
. line le_wm year, yaxis(1 2) xaxis(1 2)
|| line le_bm year
|| line diff year
|| lfit diff year
||,
ylabel(0(5)20, axis(2) gmin angle(horizontal))
ylabel(0 20(10)80, gmax angle(horizontal))
ytitle("", axis(2))
xlabel(1918, axis(2)) xtitle("", axis(2))
ytitle("Life expectancy at birth (years)")
title("White and black life expectancy")
subtitle("USA, 1900-1999")
note("Source: National Vital Statistics, Vol 50, No. 6"
"(1918 dip caused by 1918 Influenza Pandemic)")
legend(label(1 "White males") label(2 "Black males"))
legend(col(1) pos(3)){txt}
{it:({stata gr_example2 line4:click to run})}
{* graph line4}{...}
{pstd}
See {it:{help legend_option}} for more information about dealing with
legends.
{marker remarks4}{...}
{title:Cautions}
{pstd}
Be sure that the data are in the order of the {it:x} variable, or specify
{cmd:line}'s {cmd:sort} option. If you do neither, you will get something
that looks like the scribblings of a child:
{cmd:. sysuse auto, clear}
{cmd:. line mpg weight}
{it:({stata "gr_example auto: line mpg weight":click to run})}
{* graph grline2}{...}
{title:Also see}
{psee}
Manual: {bf:[G] graph twoway line}
{psee}
Online: {helpb scatter};
{helpb twoway mband},
{helpb twoway mspline},
{helpb twoway lfit},
{helpb twoway qfit},
{helpb twoway fpfit}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -