I have combined five horizontal barcharts into one figure with a common legend using grc1leg. My code is inserted below and I have attached the resulting graph.
Overall it works fine and produces the desired graph - however, I am struggling with the following issues related to formatting:
input quest str25 q a1 a2 a3 a4
1 "Model A" 7 9 53 211
1 "Model B" 4 8 58 210
1 "Model C" 0 13 65 202
2 "Model A" 49 25 110 96
2 "Model B" 24 28 150 78
2 "Model C" 2 17 138 123
3 "Model A" 34 19 110 117
3 "Model B" 16 34 143 87
3 "Model C" 5 27 142 106
4 "Model A" 62 29 108 81
4 "Model B" 42 45 119 74
4 "Model C" 18 43 131 88
5 "Model A" 176 20 32 52
5 "Model B" 194 25 32 29
5 "Model C" 223 29 16 12
end
graph hbar a1-a4 if quest==1, percent over(quest, gap(1)) over(q, gap(10)) ///
stack legend(off) yscale(off) yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) ///
subtitle("Do you agree with the first question?") ///
saving(a1, replace) yscale(off) plotregion(margin( b+3 t+3)) outergap(30)
graph hbar a1-a4 if quest==2, percent over(quest, gap(1)) over(q, gap(10)) ///
stack legend(off) yscale(off) yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) ///
subtitle("Do you agree with the second question?") ///
saving(a1a, replace) yscale(off) plotregion(margin( b+3 t+3)) outergap(30)
graph hbar a1-a4 if quest==3, percent over(quest, gap(1)) over(q, gap(10)) ///
stack legend(off) yscale(off) yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) ///
subtitle("Do you agree with the third question?") ///
saving(a1b, replace) yscale(off) plotregion(margin( b+3 t+3)) outergap(30)
graph hbar a1-a4 if quest==4, percent over(quest, gap(1)) over(q, gap(10)) ///
stack legend(off) yscale(off) yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) ///
subtitle("Do you agree with the fourth question?") ///
saving(a1c, replace) yscale(off) plotregion(margin( b+3 t+3)) outergap(30)
graph hbar a1-a4 if quest==5, percent over(quest, gap(1)) over(q, gap(10)) ///
subtitle("Do you agree with the fifth question?") ///
stack legend(span rows(1) label(1 "No") label(2 "To a small degree") ///
label(3 "To some degree") label(4 "To a high degree ") ///
size(small)) ///
yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) saving(a2, replace)
grc1leg a1.gph a1a.gph a1b.gph a1c.gph a2.gph, cols(1) ///
imargin(0 0 0 0 0) ycommon xcommon legendfrom(a2.gph)
graph export "$rpath\utilitygraph_example.png", replace
exit
Overall it works fine and produces the desired graph - however, I am struggling with the following issues related to formatting:
- I would like to add some horizontal spacing so that the graph appears less condensed/squeezed (hope this sentence makes sense - English is not my first language)
- I would like the five graphs to appear similar in the combined graph (right now the Fifth graph appears smaller)
- I would like to make the legend wider
- I would like to add percentages to the bars
- I would like to move the five questions to the left
- I would like to change the font to times new roman
- I would like to remove the numbers 1-5 from the output
input quest str25 q a1 a2 a3 a4
1 "Model A" 7 9 53 211
1 "Model B" 4 8 58 210
1 "Model C" 0 13 65 202
2 "Model A" 49 25 110 96
2 "Model B" 24 28 150 78
2 "Model C" 2 17 138 123
3 "Model A" 34 19 110 117
3 "Model B" 16 34 143 87
3 "Model C" 5 27 142 106
4 "Model A" 62 29 108 81
4 "Model B" 42 45 119 74
4 "Model C" 18 43 131 88
5 "Model A" 176 20 32 52
5 "Model B" 194 25 32 29
5 "Model C" 223 29 16 12
end
graph hbar a1-a4 if quest==1, percent over(quest, gap(1)) over(q, gap(10)) ///
stack legend(off) yscale(off) yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) ///
subtitle("Do you agree with the first question?") ///
saving(a1, replace) yscale(off) plotregion(margin( b+3 t+3)) outergap(30)
graph hbar a1-a4 if quest==2, percent over(quest, gap(1)) over(q, gap(10)) ///
stack legend(off) yscale(off) yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) ///
subtitle("Do you agree with the second question?") ///
saving(a1a, replace) yscale(off) plotregion(margin( b+3 t+3)) outergap(30)
graph hbar a1-a4 if quest==3, percent over(quest, gap(1)) over(q, gap(10)) ///
stack legend(off) yscale(off) yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) ///
subtitle("Do you agree with the third question?") ///
saving(a1b, replace) yscale(off) plotregion(margin( b+3 t+3)) outergap(30)
graph hbar a1-a4 if quest==4, percent over(quest, gap(1)) over(q, gap(10)) ///
stack legend(off) yscale(off) yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) ///
subtitle("Do you agree with the fourth question?") ///
saving(a1c, replace) yscale(off) plotregion(margin( b+3 t+3)) outergap(30)
graph hbar a1-a4 if quest==5, percent over(quest, gap(1)) over(q, gap(10)) ///
subtitle("Do you agree with the fifth question?") ///
stack legend(span rows(1) label(1 "No") label(2 "To a small degree") ///
label(3 "To some degree") label(4 "To a high degree ") ///
size(small)) ///
yline(20 40 60 80 ,lwidth(0.25) lcolor(black)) saving(a2, replace)
grc1leg a1.gph a1a.gph a1b.gph a1c.gph a2.gph, cols(1) ///
imargin(0 0 0 0 0) ycommon xcommon legendfrom(a2.gph)
graph export "$rpath\utilitygraph_example.png", replace
exit
Comment