Hello,
I'm making a combined graph. There are 6 graphs in total, with two rows of 3. The top 3 show distributions of survey scores belonging to a control group, and the bottom 3 show the distributions for the treatment group.
The problem i'm running into is that if I use graph combine I end up with the legend for the control group half way between the two rows and the legend for the treatment group at the bottom of the plot region (where I want both keys and text to be). If I use grc1leg (SSC) it will only include one of the keys and associated text because the legend for the single graph (that grc1leg draws from) is only for a single variable.
I've tried forcing the histogram to show two keys, by specifying lab(1 "label one") and lab(2 "label two"). This gives me the text that I want for the second key, but naturally only one key shows up when I render the graphs. What I want is for there to be a legend at the bottom of the combined graph, with two keys (one gs7 and another gs13) indicating that the top row is for the control group and the bottom row is for the treatment group.
I share data and code below to replicate the problem.
A second problem is that I only want there to be xtitles for one of the rows. I've placed these on the bottom of the top row so it looks like they're in the middle of the plot region, and are associated vertically with each column. However, when doing this the xtitles are very close to the top row's x-axis. I can specify xscale(titlegap(*5)) and this does increase the space between the x-axis and the xtitle, but then it squashes the top row to accommodate for the space i've created. This makes comparing the top and bottom rows visually harder. Any ideas on this would also be gratefully appreciated.
I'm making a combined graph. There are 6 graphs in total, with two rows of 3. The top 3 show distributions of survey scores belonging to a control group, and the bottom 3 show the distributions for the treatment group.
The problem i'm running into is that if I use graph combine I end up with the legend for the control group half way between the two rows and the legend for the treatment group at the bottom of the plot region (where I want both keys and text to be). If I use grc1leg (SSC) it will only include one of the keys and associated text because the legend for the single graph (that grc1leg draws from) is only for a single variable.
I've tried forcing the histogram to show two keys, by specifying lab(1 "label one") and lab(2 "label two"). This gives me the text that I want for the second key, but naturally only one key shows up when I render the graphs. What I want is for there to be a legend at the bottom of the combined graph, with two keys (one gs7 and another gs13) indicating that the top row is for the control group and the bottom row is for the treatment group.
I share data and code below to replicate the problem.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(treatment q1 q2 q3 newobs) 1 14 14 12 0 1 13 8 7 0 1 9 11 6 0 1 11 6 11 0 1 8 10 11 0 1 8 6 8 0 0 . . . 0 0 2 5 4 0 0 9 14 14 0 0 2 4 4 0 0 5 5 4 0 0 . . . 0 1 4 8 5 0 1 13 14 . 0 1 5 12 5 0 1 2 4 7 0 1 4 4 2 0 1 11 9 10 0 1 10 8 7 0 1 4 6 4 0 1 14 14 13 0 1 13 10 10 0 1 6 11 14 0 0 6 9 10 0 0 4 5 2 0 0 8 10 11 0 0 8 11 4 0 0 9 10 10 0 0 5 7 4 0 0 14 14 11 0 0 11 11 10 0 0 10 11 11 0 0 10 13 10 0 1 14 10 14 1 1 14 13 10 1 1 14 10 12 1 1 12 6 6 1 1 12 8 6 1 1 10 8 8 1 1 8 8 8 1 1 9 8 8 1 1 9 8 7 1 1 10 8 11 1 1 8 8 9 1 1 10 8 8 1 1 10 8 9 1 1 11 8 8 1 1 10 10 8 1 1 11 7 8 1 1 10 7 8 1 1 11 7 6 1 0 . . . 1 0 . . . 1 0 . . . 1 0 2 5 4 1 0 2 4 5 1 0 2 4 4 1 0 8 10 13 1 0 10 14 14 1 0 11 13 11 1 0 2 5 4 1 0 2 5 5 1 0 2 4 5 1 0 4 5 5 1 0 5 4 4 1 0 5 5 4 1 0 . . . 1 0 . . . 1 0 . . . 1 1 5 6 4 1 1 4 7 5 1 1 4 7 4 1 1 14 10 . 1 1 12 10 . 1 1 11 10 . 1 1 5 11 5 1 1 4 13 4 1 1 4 14 4 1 1 2 4 8 1 1 2 5 8 1 1 2 5 6 1 1 5 4 2 1 1 4 5 2 1 1 4 4 2 1 1 11 10 8 1 1 10 10 10 1 1 9 9 9 1 1 9 9 7 1 1 9 11 7 1 1 11 9 7 1 1 5 7 5 1 1 4 8 4 1 1 5 7 5 1 1 14 11 13 1 1 13 12 13 1 1 11 12 14 1 1 14 10 14 1 1 14 10 14 1 1 12 12 12 1 1 6 14 14 1 end
Code:
quietly{ foreach var of varlist q1 q2 q3{ summarize `var' if treat==0 local Cmin2SD = round(`=`r(mean)' - (`r(sd)'*2)', 0.1) local Cmin1SD = round(`=`r(mean)' - `r(sd)'', 0.1) local Cmean = round(`r(mean)', 0.1) local Cplus1SD = round(`=`r(mean)' + `r(sd)'', 0.1) local Cplus2SD = round(`=`r(mean)' + (`r(sd)'*2)', 0.1) summarize `var' if treat==1 local Tmin2SD = round(`=`r(mean)' - (`r(sd)'*2)', 0.1) local Tmin1SD = round(`=`r(mean)' - `r(sd)'', 0.1) local Tmean = round(`r(mean)', 0.1) local Tplus1SD = round(`=`r(mean)' + `r(sd)'', 0.1) local Tplus2SD = round(`=`r(mean)' + (`r(sd)'*2)', 0.1) if "`var'"=="q1" local ytit "Frequency of response" if "`var'"!="q1" local ytit "" if "`var'"=="q1" local xtit "Scale one" if "`var'"=="q2" local xtit "Scale two" if "`var'"=="q3" local xtit "Scale three" hist `var' if treat==0, discrete col(gs7) graphregion(col(white)) bgcol(white) freq xaxis(1 2) yaxis(1 2) ylabel(0(2)16, grid format(%9.0f) angle(0)) /// xlabel(`Cmean' "mean" `Cmin2SD' "-2 s.d." `Cmin1SD' "-1 s.d." `Cplus1SD' "+1 s.d." `Cplus2SD' "+2 s.d.", axis(2) grid gmax angle(-0.0001) labgap(3)) /// xtitle("", axis(2)) xtitle("`xtit'", axis(1)) xlabel(0(1)14) ytitle("", axis(2)) ytitle("`ytit'", axis(1)) lcol(white) /// ysc(r(0/16)) legend(lab(1 "control") lab(2 "treatment") region(c(none)) order( 1 2 ) size(3) cols(2)) ylab(, nolabel noticks axis(2)) name(`var'_0, replace) nodraw hist `var' if treat==1, discrete col(gs13) graphregion(col(white)) bgcol(white) freq xaxis(1 2) yaxis(1 2) ylabel(0(1)16, grid format(%9.0f) angle(0)) /// xlabel(`Tmean' "mean" `Tmin2SD' "-2 s.d." `Tmin1SD' "-1 s.d." `Tplus1SD' "+1 s.d." `Tplus2SD' "+2 s.d.", axis(2) grid gmax angle(-0.0001) labgap(3)) /// xtitle("", axis(2)) xtitle("", axis(1)) xlabel(0(1)14) ytitle("", axis(2)) ytitle("`ytit'", axis(1)) lcol(white) /// ysc(r(0/16)) legend(lab(1 "control") lab(2 "treatment") region(c(none)) order( 1 2 ) size(3) cols(2)) ylab(, nolabel noticks axis(2)) name(`var'_1, replace) nodraw } } grc1leg q1_0 q2_0 q3_0, graphregion(color(white)) leg(q1_0) /// imargin(vsmall) title("", color(black) size(med)) l1("", col(black) size(small)) cols(3) xsize(12) ysize(4) /// name(combContr, replace) graph display combContr, xsize(12) ysize(4) grc1leg q1_1 q2_1 q3_1, graphregion(color(white)) leg(q1_1) /// imargin(vsmall) title("", color(black) size(med)) l1("", col(black) size(small)) cols(3) xsize(12) ysize(4) /// name(combTreat, replace) graph display combTreat, xsize(12) ysize(4) grc1leg combContr combTreat, graphregion(color(white)) imargin(vsmall) /// title("", color(black) size(small)) l1("", col(black) size(small)) cols(1) xsize(12) ysize(8) graph combine combContr combTreat, graphregion(color(white)) imargin(vsmall) /// title("", color(black) size(small)) l1("", col(black) size(small)) cols(1) xsize(12) ysize(8)
Comment