I hope this is not a repeat question. I'm working on combining two graph panels side by side that will use the same legend. If I position the legend inside one of the panels, the panels are not distorted, but the legend is not (to my mind) positioned intuitively. I would like to position the legend outside the right-hand panel, but when I do so, the right-hand panel is narrowed, making it hard to read and mismatched with the left-hand panel. I'd be grateful for suggestions on how to position the graph outside the right-hand panel and have the panels displayed with identical widths as they are when I place the legend inside. As a secondary bonus question, I'd be grateful for suggestions on how to smooth the curve in the left-hand panel. Lowess doesn't quite do it (perhaps needs more data points?).
Thanks! -Doug
clear
/***********Sets up the data********************/
set obs 10
gen year=_n
la var year "Year"
gen couns1=0
replace couns1=3079.18381538462 if (year/5)==round(year/5)
gen couns2=0
replace couns2=2*3079.18381538462 if (year/5)==round(year/5)
gen onetime=0
replace onetime=94098.1487 if year==1
gen yrcostN75=onetime+couns1+75*220.157112683779
gen yrcostN151=onetime+couns1+151*220.157112683779
gen yrcostN302=onetime+couns2+302*220.157112683779
foreach x of numlist 75 151 302 {
gen cumtotcostN`x'yr = sum(yrcostN`x')
gen cumN`x'=year*`x'
gen perperscostN`x'yr=cumtotcostN`x'yr/cumN`x'
replace cumtotcostN`x'yr=cumtotcostN`x'yr/1000
la var perperscostN`x'yr "`x' patients/year"
la var cumtotcostN`x'yr "`x' patients/year"
}
/************************************************/
/*Pay attention here for graphics issues*/
/*Legend inside panel*/
twoway line cumtotcostN75yr cumtotcostN151yr cumtotcostN302yr year, legend(ring(0) position(10)) saving(cumulative, replace) ytitle(`"(`=char(36)'1,000s)"') title("B. Cumulative Total Costs")
twoway line perperscostN75yr perperscostN151yr perperscostN302yr year, saving(perperson, replace) legend(off) ytitle("(`=char(36)')") title("A. Per Person Costs")
gr combine perperson.gph cumulative.gph
/*Legend outside panel*/
twoway line cumtotcostN75yr cumtotcostN151yr cumtotcostN302yr year, legend(ring(1) position(3)) saving(cumulative, replace) ytitle(`"(`=char(36)'1,000s)"') title("B. Cumulative Total Costs")
twoway line perperscostN75yr perperscostN151yr perperscostN302yr year, saving(perperson, replace) legend(off) ytitle("(`=char(36)')") title("A. Per Person Costs")
gr combine perperson.gph cumulative.gph
Thanks! -Doug
clear
/***********Sets up the data********************/
set obs 10
gen year=_n
la var year "Year"
gen couns1=0
replace couns1=3079.18381538462 if (year/5)==round(year/5)
gen couns2=0
replace couns2=2*3079.18381538462 if (year/5)==round(year/5)
gen onetime=0
replace onetime=94098.1487 if year==1
gen yrcostN75=onetime+couns1+75*220.157112683779
gen yrcostN151=onetime+couns1+151*220.157112683779
gen yrcostN302=onetime+couns2+302*220.157112683779
foreach x of numlist 75 151 302 {
gen cumtotcostN`x'yr = sum(yrcostN`x')
gen cumN`x'=year*`x'
gen perperscostN`x'yr=cumtotcostN`x'yr/cumN`x'
replace cumtotcostN`x'yr=cumtotcostN`x'yr/1000
la var perperscostN`x'yr "`x' patients/year"
la var cumtotcostN`x'yr "`x' patients/year"
}
/************************************************/
/*Pay attention here for graphics issues*/
/*Legend inside panel*/
twoway line cumtotcostN75yr cumtotcostN151yr cumtotcostN302yr year, legend(ring(0) position(10)) saving(cumulative, replace) ytitle(`"(`=char(36)'1,000s)"') title("B. Cumulative Total Costs")
twoway line perperscostN75yr perperscostN151yr perperscostN302yr year, saving(perperson, replace) legend(off) ytitle("(`=char(36)')") title("A. Per Person Costs")
gr combine perperson.gph cumulative.gph
/*Legend outside panel*/
twoway line cumtotcostN75yr cumtotcostN151yr cumtotcostN302yr year, legend(ring(1) position(3)) saving(cumulative, replace) ytitle(`"(`=char(36)'1,000s)"') title("B. Cumulative Total Costs")
twoway line perperscostN75yr perperscostN151yr perperscostN302yr year, saving(perperson, replace) legend(off) ytitle("(`=char(36)')") title("A. Per Person Costs")
gr combine perperson.gph cumulative.gph

Comment