Graphics 使用组合图时控制图的大小
我正在尝试使用Graphics 使用组合图时控制图的大小,graphics,stata,Graphics,Stata,我正在尝试使用图形组合在Stata中组合四个图形 结果如下图所示: 所有四个图形的大小应相同,但由于水平ytitle,前两个图形被压缩。有没有办法控制图形组合的方式重新调整图形的大小 我尝试了ysize和xsize,但这似乎被graph combine覆盖了 您可以在下面找到生成图形的代码: sysuse auto, clear graph drop _all # delimit ; * First 2 figures; twoway (line weight mpg if foreign
图形组合
在Stata中组合四个图形
结果如下图所示:
所有四个图形的大小应相同,但由于水平ytitle
,前两个图形被压缩。有没有办法控制图形组合的方式
重新调整图形的大小
我尝试了ysize
和xsize
,但这似乎被graph combine
覆盖了
您可以在下面找到生成图形的代码:
sysuse auto, clear
graph drop _all
# delimit ;
* First 2 figures;
twoway (line weight mpg if foreign == 1,
sort ytitle("Some longer ytitle", orientation(horizontal))
title("Foreign", box bexpand) yla(, ang(h)) xtitle("")
xlabel(,noticks) name(A1, replace ) graphregion(color(gs16)));
twoway (line weight mpg if foreign == 1, sort
ytitle("short", orientation(horizontal)) yla(, ang(h)) xtitle("")
xlabel(,noticks) name(A2, replace ) graphregion(color(gs16)));
graph combine A1 A2, cols(1) name(A, replace) imargin(b=0 t=0);
* Second 2 figures;
twoway (line weight mpg if foreign == 0, sort ytitle("")
title("Domestic", box bexpand) xtitle("") xlabel(,noticks)
name(B1, replace ) graphregion(color(gs16)) );
twoway (line weight mpg if foreign == 0, sort ytitle("") xtitle("")
xlabel(,noticks) name(B2, replace ) graphregion(color(gs16)));
graph combine B1 B2, cols(1) name(B, replace) imargin(b=0 t=0);
* Combining the two
graph combine A B ;
您需要将每个
yttle
的方向更改为垂直,并仅按所需顺序组合图形一次
以下将根据您的要求提供相同大小的数字:
sysuse auto, clear
graph drop _all
# delimit ;
* First 2 figures;
twoway (line weight mpg if foreign == 1,
sort ytitle("Some longer ytitle", orientation(vertical))
title("Foreign", box bexpand) yla(, ang(h)) xtitle("")
xlabel(,noticks) name(A1, replace ) graphregion(color(gs16)));
twoway (line weight mpg if foreign == 1, sort
ytitle("short", orientation(vertical)) yla(, ang(h)) xtitle("")
xlabel(,noticks) name(A2, replace ) graphregion(color(gs16)));
* Second 2 figures;
twoway (line weight mpg if foreign == 0, sort ytitle("")
title("Domestic", box bexpand) xtitle("") xlabel(,noticks)
name(B1, replace ) graphregion(color(gs16)) );
twoway (line weight mpg if foreign == 0, sort ytitle("") xtitle("")
xlabel(,noticks) name(B2, replace ) graphregion(color(gs16)));
* Combining the 4 graphs;
graph combine A1 B1 A2 B2;
我还建议第一列中的图形以垂直角度旋转其yaxis
标记标签,以便与第二列中的图形匹配:
请注意,通过减小两个轴的刻度值标签的大小,可以使ytitle
更加突出。您可能需要调整ytitle
和yaxis
勾选标签之间的间距
编辑: 你可以用“蛮力”来做你喜欢做的事,但你永远也得不到你想要的。这是因为变量
ytitle
length会影响整个图形区域
快速解决方案如下所示:
sysuse auto, clear
graph drop _all
# delimit ;
* First 2 figures;
twoway (line weight mpg if foreign == 1,
sort ytitle("Some longer ytitle", orientation(h))
title("Foreign", box bexpand) yla(, ang(h)) xtitle("")
xlabel(,noticks) name(A1, replace ) graphregion(color(gs16)));
twoway (line weight mpg if foreign == 1, sort
ytitle(" short", orientation(h)) yla(, ang(h)) xtitle("")
xlabel(,noticks) name(A2, replace ) graphregion(color(gs16)));
* Second 2 figures;
twoway (line weight mpg if foreign == 0, sort ytitle("")
title("Domestic", box bexpand) xtitle("") xlabel(,noticks)
name(B1, replace ) graphregion(color(gs16)) );
twoway (line weight mpg if foreign == 0, sort ytitle("") xtitle("")
xlabel(,noticks) name(B2, replace ) graphregion(color(gs16)));
* Combining the 4 graphs;
graph combine A1 B1 A2 B2, xsize(7);
谢谢,我就是这样开始的。然而,有人要求我提供横向数据。你认为有可能吗?刚刚编辑了我的帖子。如果你发现答案是有用的,请考虑用支票来接受它。在
fxsize
,强制Stata覆盖x轴的默认长度。玩数字游戏可能会得到一个更对称的数字。我在我的帖子中说的是,你们需要玩各种各样的选项来接近它。但是,即使使用fxsize
,您也不可能得到您想要的结果。
twoway (line weight mpg if foreign == 0, sort ytitle("")
title("Domestic", box bexpand) xtitle("") xlabel(,noticks)
name(B1, replace ) graphregion(color(gs16) margin(r=22)));
twoway (line weight mpg if foreign == 0, sort ytitle("") xtitle("")
xlabel(,noticks) name(B2, replace ) graphregion(color(gs16) margin(r=22)));