如何用Stata的graph命令绘制双柱状图和折线图的组合
时间: 2024-03-31 18:33:54 浏览: 333
频数图的制作-stata入门教程
可以使用Stata的`graph twoway`命令来绘制双柱状图和折线图的组合。下面是一个示例代码:
```
sysuse auto, clear
graph twoway (bar mpg weight, barwidth(0.4) barlabel(foreground(white))) ///
(line price, yaxis(2) lcolor(blue) lpattern(dash)) ///
legend(order(1 "MPG" 2 "Weight" 3 "Price") region(color(white))) ///
ytitle("MPG and Weight" "Price") xtitle("Car Model") ///
title("MPG, Weight and Price by Car Model") ///
scheme(s1color)
```
上述代码中,`graph twoway`命令用于绘制双柱状图和折线图的组合。其中,`(bar mpg weight, barwidth(0.4) barlabel(foreground(white)))`用于绘制双柱状图,`barwidth(0.4)`参数指定柱子宽度为0.4,`barlabel(foreground(white))`参数指定柱子标签颜色为白色;`(line price, yaxis(2) lcolor(blue) lpattern(dash))`用于绘制折线图,`yaxis(2)`参数指定折线图使用右侧的y轴,`lcolor(blue)`参数指定折线颜色为蓝色,`lpattern(dash)`参数指定折线类型为虚线。`legend(order(1 "MPG" 2 "Weight" 3 "Price") region(color(white)))`用于设置图例,`order(1 "MPG" 2 "Weight" 3 "Price")`参数指定图例中条目的顺序和标签,`region(color(white))`参数指定图例背景颜色为白色。`ytitle("MPG and Weight" "Price")`用于设置y轴标题,`xtitle("Car Model")`用于设置x轴标题,`title("MPG, Weight and Price by Car Model")`用于设置图表标题,`scheme(s1color)`用于设置图表样式。
阅读全文