Dear Statalist,
I'm having an issue when using graph combine, where sub-graphs aren't aligned along their x-axes. Please see below:


I would by able to get correct alignment by doing scatter lexp loggnp, by(region), but due to features not in this example, I need to plot each subgraph individually and later graph combine them.
If anyone has any thoughts, they would be greatly appreciated.
Thank you,
Andrew Maurer
I'm having an issue when using graph combine, where sub-graphs aren't aligned along their x-axes. Please see below:
Code:
sysuse lifeexp, clear
gen loggnp = log10(gnppc)
replace lexp = 10000 in 1 // to illustrate a different ylabel width for one subgraph
label var loggnp "Log base 10 of GNP per capita"
*****************
* First attempt *
*****************
/*
Problems:
1) I don't want xtitles and xlabels repeated on each axis
(axes should be aligned along x with a single x-axis at bottom)
2a) x-axes aren't being aligned correctly, since the y-axis
for Eur & C.Asia is wider (max value of 10000) than the other y-axes
(max values of only 2 digits [80 and 75])
*/
levelsof region, local(levs)
foreach r of local levs {
scatter lexp loggnp if region == `r', ///
name(g`r', replace) ylabel(, angle(0))
}
graph combine g1 g2 g3, cols(1) xcommon imargin(zero)
Code:
******************
* Second attempt *
******************
/*
Fixed Problem 1, but Problem 2 is still an issue
Problem
2b) not only is the difference in width of the widest y-label between sub-graphs
an issue, but the ytitle widths are also throwing off the x-alignment
*/
levelsof region, local(levs)
foreach r of local levs {
if `r' != 3 local xlabel none
else local xlabel
scatter lexp loggnp if region == `r', ///
name(g`r', replace) ylabel(, angle(0)) ///
xtitle("") xlabel(`xlabel') ///
ytitle("`: label region `r''", orientation(horizontal))
}
graph combine g1 g2 g3, cols(1) xcommon imargin(zero) ///
b1title("Log base 10 of GNP per capita") ///
l1title("Life expectancy at birth")
I would by able to get correct alignment by doing scatter lexp loggnp, by(region), but due to features not in this example, I need to plot each subgraph individually and later graph combine them.
If anyone has any thoughts, they would be greatly appreciated.
Thank you,
Andrew Maurer

That point almost has to be an error. I think if you correct or remove that point, the rest of the data will settle out properly, all three graphs will have a common and reasonable vertical scale, and the other problems you are worrying about will solve themselves.
Comment