最近看了一个帖子,求助分组绘图,一时兴起,画了几张图,供大家参考:数据举例:
- * Example generated by -dataex-. To install: ssc install dataex
- clear
- input double(d grade health)
- 182.49
- 19 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
- 28 2.7
- 292.75
- 2 10 2.6
- 2 11 2.5
- 2 122.25
- 2 13 2.1
- 2 142.05
- 2 151.98
- 2 16 1.8
- 383.05
- 39 2.9
- 3 10 2.8
- 3 11 2.7
- 3 122.35
- 3 13 2.3
- 3 142.25
- 3 152.23
- 3 16 2
- 483.27
- 49 3.1
- 4 103.05
- 4 11 2.9
- 4 12 2.6
- 4 132.48
- 4 142.38
- 4 152.45
- 4 16 2.2
- 583.25
- 593.18
- 5 103.05
- 5 11 3
- 5 12 2.8
- 5 13 2.7
- 5 142.72
- 5 152.68
- 5 162.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+")
复制代码
最终效果如下:
上面几种分组绘图方案,你更喜欢哪一个呢?