如何对齐组合 Stata 条形图中的 x 轴?

How to align the x-axis in combined Stata bar graphs?

我正在尝试将多个条形图相互堆叠。我使用两个常量变量来强制 Stata 以颜色打印第一个 over 选项并使用图例。不幸的是,如果我使用 graph combine,Stata 不会自动对齐不同图形的 x 轴。有没有正确的方法来左对齐 x 轴? 我通过在 "con2" 的标签中添加空格找到了一个 hack,但这不是很准确并且在很大程度上取决于所使用的字体。

这是一个工作示例:

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)

您正在绘制单独的图表,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

该设备适用于多个面板,而不仅仅是两个。您可能需要在轴标签上做一些工作,如此处所示。