Hello Statalisters,
I would like to underlay a histogram onto a marginsplot so conceptually it looks something like the attached.
In an ideal world there are a few things I would like to change: 1) i'd like the yaxis for the histogram (currently the outermost yaxis) to be on the right hand side of the graph; 2) i'd like the xaxis to start at 1 and not 0; and 3) i'd like the bars to be much fainter and underlay (not overlay) the marginsplot.
My code to produce this is
The below option for addplot seems to be what I need to make the histogram underlay and not overlay, but it is not having any effect. W.r.t. moving the yaxis to the r.h.s. and forcing the histogram to start at 1, my investigation has shown this doesn't seem possible using addplot.
I tried using parmest (SCC) and something like this
but cannot find an option on parmest to get N by groups of taker_consec_worked which I would need in order to add the twoway bar for frequency.
I would like to underlay a histogram onto a marginsplot so conceptually it looks something like the attached.
In an ideal world there are a few things I would like to change: 1) i'd like the yaxis for the histogram (currently the outermost yaxis) to be on the right hand side of the graph; 2) i'd like the xaxis to start at 1 and not 0; and 3) i'd like the bars to be much fainter and underlay (not overlay) the marginsplot.
My code to produce this is
Code:
reg ct_proctmsec i.taker_consec_worked if taker_consec_worked<12 matrix a = r(table) loc ylin = a[1,`= colsof(a)'] margins, at(taker_consec_worked=(1 2 3 4 5 6 7 8 9 10 11)) #delimit ; marginsplot, plotopts(mcol("0 174 239") msize(2) lcol("0 174 239")) ciopts(lcol("237 125 49")) graphregion(col(white)) yline(`ylin', lcol(maroon)) xlabel(1 2 3 4 5 6 7 8 9 10 11, valuelabel labsize(small) angle(0.01)) ylab(, angle(0)) ytitle("Seconds", size(medsmall)) bgcol(white) xtitle("Number of consecutive days worked", size(medsmall)) ysc(titlegap(*5)) xsc( titlegap(*10)) title("Time between call receipt and queue", col(black) size(medsmall)) addplot(hist taker_consec_worked if taker_consec_worked<=11, freq yaxis(2) below start(1) width(1) legend(off)) name(gph_26, replace) ; #delimit cr
I tried using parmest (SCC) and something like this
Code:
reg ct_proctmsec i.taker_consec_worked if taker_consec_worked<12
matrix a = r(table)
loc ylin = a[1,`= colsof(a)']
margins, at(taker_consec_worked=(1 2 3 4 5 6 7 8 9 10 11)) post
preserve
parmest, norestore // SCC
gen eqno = _n
#delimit ;
twoway (scatter estimate eqno, color("0 174 239") msize(3))
(rcap min95 max95 eqno, col("237 125 49"))
(bar N eqno, freq), //I don't have this N value yet... but would like it
;
#delimit cr
restore
Comment