Imasasor 发表于 2014-10-11 10:05
stata做出的森林图,导出eps格式,该格式为矢量图格式,用adobe illustrator打开,可以随心所欲的随便修饰 ...
代码:[code]%let name=forest_plot;
filename odsout '.';
data forest_data;
input Subgroup $1-13 No_Pct $14-23 HazardRatio 24-26 LowerCL 28-30 UpperCL 32-34 PCI 37-40 other 42-45 P 49-52;
data_order=_N_;
Q1=HazardRatio-0.01;
Q3=HazardRatio+0.01;
datalines;
Overall 2166(100) 1.3 0.8 1.6 17.2 15.6
Age 0.05
<=65 Yr 1534( 71) 1.5 1.1 1.9 17 13.2
>65 Yr 632( 29) 0.8 0.5 1.3 17.8 21.3
Sex 0.13
Male 1690( 78) 1.5 1.1 1.9 16.8 13.5
Female 476( 22) 0.8 0.5 1.3 18.3 22.9
;
run;
/*
User-defined format so that aeseq number prints as aedecod text.
(this way, the axis will be in the numeric order, but will show the text values)
*/
proc sql;
create table foo as select unique data_order, subgroup from forest_data;
quit; run;
data control; set foo (rename=(data_order=start subgroup=label));
fmtname = 'forfmt';
type = 'N';
end = START;
run;
proc format lib=work cntlin=control;
run;
/* Annotate the box & whiskers */
data anno_box; set forest_data;
length function color $8 style $20 text $30;
when='a'; hsys='3';
xsys='2'; ysys='2'; color=''; size=.; line=.;
/* draw whiskers */
function='move'; x=LowerCL; y=data_order; output;
function='draw'; size=.01; x=UpperCL; output;
/* draw solid box */
function='move'; x=q1; y=data_order; output;
function='move'; y=y-.03; output;
function='bar'; style='solid'; color='gray77'; line=0;
y=y+2*.03; x=q3; output;
/* draw border around box */
function='move'; x=q1; y=data_order; output;
function='move'; y=y-.03; output;
function='bar'; style='empty'; color='black'; line=0;
y=y+2*.03; x=q3; output;
if subgroup='Overall' then do;
color='cx6495ed';
/* dashed line */
xsys='2'; ysys='1';
x=hazardratio;
y=0; function='move'; output;
y=100; function='draw'; size=.01; line=3; output;
end;
run;
/* annotate the little lines to denote treatment & placebo */
data anno_lines;
length function color $8 style $20;
xsys='2'; ysys='1'; when='a'; color='black';
x=1.0;
y=0; function='move'; output;
y=104; function='draw'; output;
x=100;
y=0; function='move'; output;
y=104; function='draw'; output;
run;
data anno_headers;
length function color $8 style $20 text $30;
xsys='1'; ysys='1'; when='a'; size=1.5;
function='label'; style='albany amt';
y=115;
x=0; text='Subgroup'; output;
x=20; text='No. of Patients (%)'; output;
x=50; text='Hazard Ratio'; output;
x=87; text='4-Yr Cumulative Event Rate'; output;
size=1;
y=110; text='Medical Therapy'; output;
size=1.2;
y=105;
x=95; text='P value'; output;
x=x-8; text='Group'; output;
x=x-8; text='PCI Group'; output;
xsys='2'; size=1;
x=1.5; text='---Medical Therapy Better--->'; output;
x=.5; text='<---PCI Better---'; output;
run;