Hi Statalists,

I am combining four graphs with datetime on the x-axes. The individual graphs have almost no margin on either side of the plot region. This is what I want. However, after graph combine, the margin has increased.

Individual graph with margin as I want it:

Array

Combined graphs with much larger margins (it's about the bit before 21:30, and the bit after let's say 05:00):
Array


How can I keep the margin small after I use graph combine?

Here's the code that creates the individual and combined graphs:
Code:
clear
insobs 6768
egen datetime1 = seq()
gen double datetime2 = clock("28-07-2021 21:30:18", "DM20Y hms")
gen double datetime = datetime2 + (datetime1*4*1000)
gen spo2 = runiformint(80,100)
gen hr = runiformint(50,110)
gen ss = runiformint(0,4)
gen bp = runiformint(0,6)

sum datetime
*local min_xlabel = `r(min)' - (`r(min)'-(3600000*int(`r(min)'/3600000)))
local min_xlabel = `r(min)'
local max_xlabel = `r(max)'

twoway ///
    (line spo2 datetime, lcolor("18 22 70%100") lwidth(vthin) xaxis(1) cmissing(n)), ///
    yscale(range(60 100)) ///
    ytitle("SpO2 (%)", axis(1) size(small)) /// xtitle(, axis(2) color(%0) size(zero)) ///xtitle(, axis(1) color(%0) size(zero)) ///
    graphregion(lwidth(none) ilwidth(none) lcolor(none) fcolor(white)) ///
    plotregion(fcolor(white) lcolor(white) lwidth(none) ilwidth(none) margin(zero)) ///
    xlabel(`min_xlabel' (3600000) `max_xlabel', grid glcolor(black%10) axis(1) format(%tcHH:MM) labsize(small) labcolor(black%100)) ///    
    ylabel(60(10)100, angle(horizontal) labsize(small)) ///
    ylab(95 "in motion", notick add custom labcolor(white)) ///
    yline(88, lpattern(shortdash) lwidth(vthin) lcolor("255 20 66")) ///
    xtitle(, axis(1) color(%0) size(zero)) ///
    legend(off) ///
    xsize(7.09) ///   
    ysize(1.15) ///
    name("oxygen_graph", replace)

twoway ///
    (line hr datetime, lcolor("18 22 70%100") lwidth(vthin) xaxis(1) cmissing(n)), ///
    ytitle("Heart rate (bpm)", axis(1) size(small)) ///xtitle(, axis(2) color(%0) size(zero)) ///xtitle(, axis(1) color(%0) size(zero)) ///
    graphregion(lwidth(none) ilwidth(none) fcolor(white) lcolor(white)) ///
    plotregion(fcolor(white) lcolor(black) lwidth(none) ilwidth(none) margin(zero)) ///
    xlabel(`min_xlabel' (3600000) `max_xlabel', grid glcolor(black%10) axis(1) format(%tcHH:MM) labsize(small) labcolor(black%100)) ///    
    ylabel(, angle(horizontal) labsize(small)) ///
    ylab(90 "in motion", notick add custom labcolor(white)) ///
    xtitle(, axis(1) color(%0) size(zero)) ///
    legend(off) ///
    xsize(7.09) ///   
    ysize(1.15) ///
    name("hr_graph", replace)
    
twoway ///
    (area ss datetime, fcolor("18 22 70%100") lwidth(none) base(0)), ///
    yscale(reverse) ///
    ytitle("Sleep stage", axis(1) size(small)) ///xtitle(, axis(2) color(%0) size(zero)) ///xtitle(, axis(1) color(%0) size(zero)) ///
    graphregion(lwidth(none) lcolor(none) ilwidth(none) fcolor(white)) ///
    plotregion(fcolor(white) lcolor(black) lwidth(none) ilwidth(none) margin(zero)) ///
    xlabel(`min_xlabel' (3600000) `max_xlabel', grid glcolor(black%10) axis(1) format(%tcHH:MM) labsize(small) labcolor(black%100)) ///    
    ylabel(0.5 "Wake" 1.5 "REM" 2.5 "Light" 3.5 "Deep", noticks nogrid angle(horizontal) labsize(small)) ///
    ylab(1 "in motion", notick add custom labcolor(white)) ///
    xtitle(, axis(1) color(%0) size(zero)) ///
    legend(off) ///
    xsize(7.09) ///   
    ysize(3.15) ///
    name("hypnogram_graph", replace)

twoway ///
    (area bp datetime, fcolor("255 20 66%100") lwidth(none) base(0)) ///
    ,yscale(range(0(1)7) reverse) ///
    ytitle("Body position", axis(1) size(small)) ///xtitle(, axis(2) color(%0) size(zero)) ///xtitle(, axis(1) color(%0) size(zero)) ///
    graphregion(lwidth(none) lcolor(none) ilwidth(none) fcolor(white)) ///
    plotregion(fcolor(white) lcolor(black) lwidth(none) ilwidth(none) margin(zero)) ///
    xlabel(`min_xlabel' (3600000) `max_xlabel', grid glcolor(black%10) axis(1) format(%tcHH:MM) labsize(small) labcolor(black%100)) ///    
    ylabel(0.5 "in motion" 1.5 "upright" 2.5 "inclined" 3.5 "supine" 4.5 "left side" 5.5 "right side" 6.5 "prone", noticks nogrid angle(horizontal) labsize(small)) ///
    ylab(1 "in motion", notick add custom labcolor(white)) ///
    xtitle(, axis(1) color(%0) size(zero)) ///
    legend(off) ///
    xsize(7.09) ///   
    ysize(3.15) ///
    name("bodyposition_graph", replace)
    
graph combine ///
    oxygen_graph hr_graph hypnogram_graph bodyposition_graph, ///
    xcommon ///
    cols(1) ///
    graphregion(fcolor(white) lcolor(white) lwidth(none) ilwidth(none) margin(zero)) ///
    plotregion(fcolor(white) lcolor(black) lwidth(none) ilwidth(none) margin(vsmall)) ///
    imargin(zero) ///
    name(oxygen_hr_hypnogram, replace)
Thanks so much in advance.