Stata如何合并图形时只保留一个图形的图例?

Stata公司的Vince Wiggins开发了一款Stata社区命令grc1leg用于合并多个图形,与graph combine类似,但只保留一个图例。
grc1leg就是graphs combine 1 legend(Combine multiple graphs into one with a single common legend)的缩写。

安装Stata社区命令grc1leg的Stata命令如下:


net install grc1leg,from( http://www.stata.com/users/vwiggins/)
help grc1leg

绘制上图的Stata代码如下:


clear all
input quest str25 q      a1 a2 a3 a4 a5 a6
1 "Question 1"           0  2  37 45 12 4
1 "Benchmark Q1"         2  5  25 47 17 4
2 "Question 2"           1  37  2 40 17 3
2 "Benchmark Q2"         2  5  25 47  4 17
3 "Question 3"           1  2  40 37 17 3
3 "Benchmark Q3"         2  5  25 47 17 4
4 "Question 4"           1  2  37  17 3 40
4 "Benchmark Q4"         2  5  47 25 17 4
end
forvalues i = 1/4 {
graph hbar a1-a6 if quest==`i', percent over(quest, gap(1)) over(q, gap(20)) ///
stack legend(span rows(1) label(1 "Missing") label(2 "Never") label(3 "Rarely") ///
label(4 "Occasionly") label(5 "Mostly") label(6 "Always") size(small)) ///
yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) name(b`i')
}
grc1leg b1 b2 b3 b4, cols(1) imargin(0 0 0 0) ycommon xcommon legendfrom(b2)

完,本文内容交流请移步: