我正在尝试相互堆叠多个条形图。我使用两个常量变量来强制Stata打印颜色中的第一个over
选项并使用图例。不幸的是,如果我使用graph combine
,Stata不会自动对齐不同图表的x轴。有没有一种正确的方法来左对齐x轴?
我通过在“con2”标签上添加空格来找到一个黑客,但这不是很精确,并且在很大程度上取决于使用的字体。
这是一个有效的例子:
sysuse nlsw88, clear
graph drop _all
recode married south (1=100)
collapse married south, by(race)
list
gen con1 = 1
gen con2 = 1
graph bar married, horiz over(race) ///
over(con1, lab(nolab)) over(con2, relabel(1 "Married")) ///
legend(off) yscale(range(0 100)) ///
name(plot1) fysize(42)
graph bar south, horiz over(race) ///
over(con1, lab(nolab)) over(con2, relabel(1 "Lives in South")) ///
yscale(range(0 100)) ///
name(plot2)
graph combine plot1 plot2, cols(1) xcom ycom imargin(0 0 0 0)
答案 0 :(得分:1)
您正在绘制单独的图表,而graph combine
只能使它们对齐。答案是将单独的图形绘制为同一图形的单独面板,这对于重组数据很容易。
sysuse nlsw88, clear
recode married south (1=100)
collapse married south, by(race)
list
rename (married south) (what=)
reshape long what , i(race) string j(response)
replace response = "lives in South" if response == "south"
graph hbar what, over(race) over(response) asyvars
该设备适用于多个面板,而不仅仅是两个面板。您可能需要在轴标签上做一些工作,如此处所示。