Sometimes when I combine two graph panels into one figure using graph combine ..., ycommon, it extends the range of the y-axis longer than the original ranges. The following minimum working example illustrates the problem:
The original ranges are from 0 to 6.6 and 0 to 6.4, but graph combine adds a lot of extra vertical space (changing the range to go up to 8). The attached images show the issue.
I know one solution is to use max(`max_y1',`max_y2') as the upper limit of the range of each original scatterplot, then use graph combine without ycommon. Although this solution works in this minimum working example, it won't do in my actual application. Is there a way to get graph combine, ... ycommon to respect the original graph ranges without adding the extra vertical space that can be seen in the attached two-graph figure?
Code:
** graph combine adding extra yaxis space
clear
input x y1 y2
1 6.6 6.4
2 1 3
end
summarize y1, meanonly
local max_y1 = r(max)
summarize y2, meanonly
local max_y2 = r(max)
twoway scatter y1 x, yscale(range(0 `max_y1')) ylabel(0(1)6) ///
name(y1graph, replace)
twoway scatter y2 x, yscale(range(0 `max_y2')) ylabel(0(1)6) ///
name(y2graph, replace)
graph combine y1graph y2graph, ycommon
I know one solution is to use max(`max_y1',`max_y2') as the upper limit of the range of each original scatterplot, then use graph combine without ycommon. Although this solution works in this minimum working example, it won't do in my actual application. Is there a way to get graph combine, ... ycommon to respect the original graph ranges without adding the extra vertical space that can be seen in the attached two-graph figure?

Comment