1.stata图形的组成
如下图所示,该图是一张包含了大多数要素的普通stata图形,其中图形区(graph area)就是指整个图形,包括所有部分;绘图区(plot area)指的是中间由坐标轴定义的区域。从图中,我们看到一张完整的图包括标题(副标题)、图例、坐标轴和一个或多个图(下图中包含了两个散点图)。
该图的do语句为:
Sysuse auto graph twoway (scatter mpg weight if foreign==0) (scatter mpg weight if foreign==1), /// title(“Title: figure demonstrated by Qiguo Lian”) /// subtitle(“subtitle: the anatomy of a graph”) /// ytitle(“Y-axis title”) xtitle(“X-axis title”) /// note (“Note: This is the outer region or background”) /// legend(title(“Legend”)) text(35 3400 “Plot area”) |
2.stata绘图命令
Stata的各个模块命令风格均保持一致,因此,我们可以通过一个命令的学习来举一反三,这给stata用户带来了很大方便。
Stata绘图命令的通用语法格式如下:
graph-command (plot-command,plot-options)(plot-command,plot-options), graph-options graph-command plot-command , plot-options || plot-command, plot-options ||, graph-options |
上面两个命令的作用是一样的,“”“||” 是等价的分隔符,旨在将不同的绘图命令分隔开,读者可以根据自己的喜好选用。
graph-command 指的是图形类型命令,plot-command 指的是绘图命令,plot-options 指的是绘图命令选项,graph-options 指的是图形命令选项。虽然plot和graph指的都是图形,但还是有一点差别(plot的范围相对更小):plot 指图形正中间由坐标包围的区域,而graph 指的是整个图形,包括坐标内外所有的部分。
例如绘制散点图的演示命令如下:
twoway(scatter mpg weight if foreign==0) (scatter mpg weight if foreign==1) |
Stata图形类型及相关绘图命令如下表所示:
图形类型 |
绘图命令 |
二维图(散点图、线图等) |
graph twoway |
散点矩阵图 |
graph matrix |
条图 |
graph bar |
圆点图 |
graph dot |
箱式图 |
graph box |
饼图 |
graph pie |
以上就是stata图形的组成和基本的命令的相关介绍,下次小编会继续介绍stata的图形格式和坐标轴选项。
参考:廉启国编著的《stata数据统计分析教程》
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!