- * Example generated by -dataex-. To install: ssc install dataex
- clear
- input double(d grade health)
- 1 8 2.49
- 1 9 2.485
- 1 10 2.4
- 1 11 2.3
- 1 12 2.1
- 1 13 1.9
- 1 14 1.8
- 1 15 1.7
- 1 16 1.6
- 2 8 2.7
- 2 9 2.75
- 2 10 2.6
- 2 11 2.5
- 2 12 2.25
- 2 13 2.1
- 2 14 2.05
- 2 15 1.98
- 2 16 1.8
- 3 8 3.05
- 3 9 2.9
- 3 10 2.8
- 3 11 2.7
- 3 12 2.35
- 3 13 2.3
- 3 14 2.25
- 3 15 2.23
- 3 16 2
- 4 8 3.27
- 4 9 3.1
- 4 10 3.05
- 4 11 2.9
- 4 12 2.6
- 4 13 2.48
- 4 14 2.38
- 4 15 2.45
- 4 16 2.2
- 5 8 3.25
- 5 9 3.18
- 5 10 3.05
- 5 11 3
- 5 12 2.8
- 5 13 2.7
- 5 14 2.72
- 5 15 2.68
- 5 16 2.65
- end
1、twoway命令
- **加箭头**
- twoway connected health grade if d==1 || connected health grade if d==2 ///
- || connected health grade if d==3 || connected health grade if d==4 ///
- || connected health grade if d==5 ///
- || pcarrowi 1.8 12 1.98 12.5 (5) ///
- 2.2 11 2.3 11.7 (5) ///
- 2.3 10 2.62 11.14 (5) ///
- 2.9 12.8 2.66 11.9 (5) ///
- 3 11.8 2.91 11.55 (5) ///
- , ///
- text(1.78 11.7 "25-34" 2.2 10.7 "35-44" 2.3 9.7 "45-54" 2.93 13.09 "55-64" 3.03 12 "65+") ///
- xtitle("Years of Education") ytitle("Health Status(1=Excellent,5=Poor)") ///
- xlabel(8 "8 or fewer" 10 12 14 16 "16+") ///
- legend(off) scheme(s1mono)
最终效果如下:
- **加图例**
- twoway connected health grade if d==1 || connected health grade if d==2 ///
- || connected health grade if d==3 || connected health grade if d==4 ///
- || connected health grade if d==5, ///
- xtitle("Years of Education") ytitle("Health Status(1=Excellent,5=Poor)") ///
- xlabel(8 "8 or fewer" 10 12 14 16 "16+") ///
- legend(order(1 "25-34" 2 "35-44" 3 "45-54" 4 "55-64" 5 "65+") row(1)) scheme(s1mono)
最终效果如下:
2、使用bytwoway命令
- bytwoway (scatter health grade,connect(l)),by(d) aes(color msymbol lpattern) ///
- xtitle("Years of Education") ytitle("Health Status(1=Excellent,5=Poor)") ///
- xlabel(8 "8 or fewer" 10 12 14 16 "16+") ///
- legend(off)
- addplot: pcarrowi 1.8 12 1.98 12.5 (5) ///
- 2.2 11 2.3 11.7 (5) ///
- 2.3 10 2.62 11.14 (5) ///
- 2.9 12.8 2.66 11.9 (5) ///
- 3 11.8 2.91 11.55 (5) ///
- , ///
- text(1.78 11.7 "25-34" 2.2 10.7 "35-44" 2.3 9.7 "45-54" 2.93 13.09 "55-64" 3.03 12 "65+")
最终效果如下:
上面几种分组绘图方案,你更喜欢哪一个呢?



雷达卡






京公网安备 11010802022788号







