BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Manj
Fluorite | Level 6

Hi,

  I have created a forest plot as below. However I would like to make the below:

1) The CI bars in Green circle to be green in colour. 

2) would need an  Arrow under the text 'Favours Control    Favours TMT ' as shown with the red arrow .

My plot and the code attached belo:

Manj_0-1623088584431.png

 

 


data ip;
length col1 $20 grp $25 adjmn $20;

col1= 'Non-Dialysis';grp= 'Non-Dialysis';grpcd=1;catcd=1;obsid=14;Output;
col1= 'Incident Dialysis';grp= 'Incident Dialysis';grpcd=2;catcd=2;obsid=9;Output;
col1= 'Dialysis';grp= 'Dialysis';grpcd=3;catcd=3;obsid=6;Output;

col1= 'Non-Dialysis';
grp='study001 AXXAA-ND, OL, QD'; grpcd=1;catcd=1;obsid=13;
N_val= 'TMT 1801 Control 1799';
adjmn='0.01 (-0.10,0.11)';
low=-0.1;
high=0.11 ;
mean=0.01 ;
output;

col1= 'Non-Dialysis';
grp=' study001 ESA users'; grpcd=2;catcd=1;obsid=12;
N_val= 'TMT 1001 Control 1013';
adjmn='0.28 (-0.05,0.54)';
low=-0.05;
high=0.54 ;
mean=0.28;
output;

col1= 'Non-Dialysis';
grp=' study001 ESA non-users'; grpcd=3;catcd=1;obsid=11;
N_val= 'TMT 480 Control 470';
adjmn='-0.06 (-0.17,0.26)';
low=-0.17;
high=0.26 ;
mean=-0.06;
output;


col1= 'Incident Dialysis';
grp='study002 AXXAA-ID, OL, QD'; grpcd=4;catcd=2;obsid=8;
N_val= 'TMT 1481 Control 1483';
adjmn='0.23 (-0.01,0.47)';
low=-0.01;
high=0.47;
mean=0.23;
output;


col1= 'Dialysis';
grp='study003 AXXAA-D, OL, QD'; grpcd=5;catcd=3;obsid=5;
N_val= 'TMT 1481 Control 1483';
adjmn='0.23 (-0.01,0.47)';
low=-0.01;
high=0.47;
mean=0.23;
output;


col1= 'Dialysis';
grp=' study003 HD';
N_val= 'TMT 1001 Control 1013';grpcd=6;catcd=3;obsid=4;
adjmn='0.28 (-0.05,0.54)';
low=-0.05;
high=0.54 ;
mean=0.28;
output;


col1= 'Dialysis';
grp=' study003 PD';
N_val= 'TMT 480 Control 470';grpcd=7;catcd=3;obsid=3;
adjmn='-0.06 (-0.17,0.26)';
low=-0.17;
high=0.26 ;
mean=-0.06;
output;


col1= 'Dialysis';
grp='study004 AXXAA-TD, DB, TIW'; grpcd=8;catcd=3; obsid=1;
N_val= 'TMT 204 Control 203';
adjmn='0.23 (-0.01,0.47)';
low=-0.01;
high=0.47;
mean=0.23;
output;

run;

proc sort;by catcd grpcd;run;

data ip;
set ip ;
if obsid in (1,5,6,8,9,13,14) then IndtWt=0;
else indtwt=1;

if obsid in (1,5,6,8,9,13,14 ) then id=1;
else id=2;
run;

data extra;
sid=16; low=-1.5; texta=' <------ Favours control '; high=0.5; textb=' Favours TMT ------>';output;
run;

data ip;
set ip extra;
run;

 


*** CREATE FIGURE ***;
ods listing close;
ods pdf file="&g_outfile..&g_fontsize" nobookmarkgen style=idsl dpi=600 ;

 

data attrmap;
length textweight $10;
id='text'; value='1'; textcolor='Black'; textsize=7; textweight='bold'; output;
id='text'; value='2'; textcolor='Green'; textsize=6; textweight='normal'; output;
id='obsid'; value='3'; color='Green'; output;
id='obsid'; value='3'; symbolcolor='Green'; output;
run;
proc sort data=ip out=allnew;by catcd grpcd grp ;run;

proc sgplot data=ip nowall noborder nocycleattrs noautolegend dattrmap=attrmap;
styleattrs axisextent=data ;
highlow y=obsid low=low high=high/highcap=serif lowcap=serif attrid=obsid;
scatter y=obsid x=mean / markerattrs=(symbol=circlefilled size=7) attrid=obsid;
scatter y=obsid x=mean / markerattrs=(size=0) x2axis ;
refline 0 / axis=x lineattrs=(pattern=1);
refline 1.2 / axis=x lineattrs=(pattern=3);


yaxis display=none colorbands=odd colorbandsattrs=(transparency=1) offsetmin=0.02;
x2axis display=(noline noticks novalues nolabel) labelattrs=(size=8);
xaxis values=(-2 -1 0 1 2) labelattrs=(size=8) labelattrs=(size=8);
*TEXT x=low y=sid text=texta / textattrs=(size=8 weight=normal) ;
* TEXT x=high y=sid text=textb / textattrs=(size=8 weight=normal) ;

x2axis label='<-------Favours Control Favours tmt -------->' display=(noline noticks novalues) labelattrs=(size=9 weight=bold);


yaxistable grp / location=inside position=left labelattrs=(size=9 weight=bold) valueattrs=(size=9 ) textgroup=id textgroupid=text indentweight=IndtWt label=' ' labelhalign=left;
yaxistable N_val / location=inside position=left labelattrs=(size=9 weight=bold) valueattrs=(size=9 ) label='N ' textgroup=id textgroupid=text labelhalign=center;
yaxistable adjmn / location=inside position=left pad=(left=15px right=15px) labelattrs=(size=9 weight=bold) textgroup=id textgroupid=text label='Adj. Mean Hgb difference (95% CI) ' labelhalign=left valueattrs=(size=9);

run;

ods pdf close;
ods listing;

1 ACCEPTED SOLUTION

Accepted Solutions
JeffMeyers
Barite | Level 11

Here's one way to do it.  Would require some play with the padding and such if changing the file size.  I make the text with TEXT plots and then use HIGHLOW plots to make the arrows instead.  I used backfill and padding to cover up the tips of the REFLINES, but you could do highlow plots instead of REFLINE as well to make this easier.

 

For the green lines you just needed to add the MARKERCOLOR and LINECOLOR options to your attribute table.  I wasn't sure if you wanted green markers as well so you can change that if you need to.

image.png

 

data ip;
length col1 $20 grp $35 adjmn $20;
col1= 'Non-Dialysis';grp= 'Non-Dialysis';grpcd=1;catcd=1;obsid=14;
y1=13.9;text1='Favours control';x1a=-0.05;x1b=-1.5;text2='Favours TMT';x2a=0.05;x2b=1.5;
output;call missing(y1,text1,x1a,x1b,text2,x2a,x2b);
col1= 'Incident Dialysis';grp= 'Incident Dialysis';grpcd=2;catcd=2;obsid=9;Output;
col1= 'Dialysis';grp= 'Dialysis';grpcd=3;catcd=3;obsid=6;Output;

col1= 'Non-Dialysis';
grp='study001 AXXAA-ND, OL, QD'; grpcd=1;catcd=1;obsid=13;
N_val= 'TMT 1801 Control 1799';
adjmn='0.01 (-0.10,0.11)';
low=-0.1;
high=0.11 ;
mean=0.01 ;
output;

col1= 'Non-Dialysis';
grp=' study001 ESA users'; grpcd=2;catcd=1;obsid=12;
N_val= 'TMT 1001 Control 1013';
adjmn='0.28 (-0.05,0.54)';
low=-0.05;
high=0.54 ;
mean=0.28;
output;

col1= 'Non-Dialysis';
grp=' study001 ESA non-users'; grpcd=3;catcd=1;obsid=11;
N_val= 'TMT 480 Control 470';
adjmn='-0.06 (-0.17,0.26)';
low=-0.17;
high=0.26 ;
mean=-0.06;
output;


col1= 'Incident Dialysis';
grp='study002 AXXAA-ID, OL, QD'; grpcd=4;catcd=2;obsid=8;
N_val= 'TMT 1481 Control 1483';
adjmn='0.23 (-0.01,0.47)';
low=-0.01;
high=0.47;
mean=0.23;
output;


col1= 'Dialysis';
grp='study003 AXXAA-D, OL, QD'; grpcd=5;catcd=3;obsid=5;
N_val= 'TMT 1481 Control 1483';
adjmn='0.23 (-0.01,0.47)';
low=-0.01;
high=0.47;
mean=0.23;
output;


col1= 'Dialysis';
grp=' study003 HD';
N_val= 'TMT 1001 Control 1013';grpcd=6;catcd=3;obsid=4;
adjmn='0.28 (-0.05,0.54)';
low=-0.05;
high=0.54 ;
mean=0.28;
output;


col1= 'Dialysis';
grp=' study003 PD';
N_val= 'TMT 480 Control 470';grpcd=7;catcd=3;obsid=3;
adjmn='-0.06 (-0.17,0.26)';
low=-0.17;
high=0.26 ;
mean=-0.06;
output;


col1= 'Dialysis';
grp='study004 AXXAA-TD, DB, TIW'; grpcd=8;catcd=3; obsid=1;
N_val= 'TMT 204 Control 203';
adjmn='0.23 (-0.01,0.47)';
low=-0.01;
high=0.47;
mean=0.23;
output;

run;

proc sort;by catcd grpcd;run;

data ip;
set ip ;
if obsid in (1,5,6,8,9,13,14) then IndtWt=0;
else indtwt=1;

if obsid in (1,5,6,8,9,13,14 ) then id=1;
else id=2;
run;

data extra;
sid=16; low=-1.5; texta=' <------ Favours control '; high=0.5; textb=' Favours TMT ------>';output;
run;

data ip;
set ip extra;
run;

 


*** CREATE FIGURE ***;
data attrmap;
length id textweight $10 value $75. linecolor markercolor $20.;
id='text'; value='1'; textcolor='Black'; textsize=7; textweight='bold'; linecolor='black';linepattern='solid';markercolor='black';output;
id='text'; value='2'; textcolor='Green'; textsize=6; textweight='normal'; linecolor='green';linepattern='solid';markercolor='green';output;
run;
proc sort data=ip out=allnew;by catcd grpcd grp ;run;

options orientation=landscape;
ods pdf file='test.pdf' notoc bookmarkgen=no;
ods graphics / width=10in;
proc sgplot data=ip nowall noborder nocycleattrs noautolegend dattrmap=attrmap;
styleattrs axisextent=data ;
highlow y=obsid low=low high=high/ group=id highcap=serif lowcap=serif attrid=text;
scatter y=obsid x=mean / group=id markerattrs=(symbol=circlefilled size=7) attrid=text;
scatter y=obsid x=mean / markerattrs=(size=0) x2axis ;
refline 0 / axis=x lineattrs=(pattern=1);
refline 1.2 / axis=x lineattrs=(pattern=3);

text x=x1a y=y1 text=text1 / backfill fillattrs=(color=white) pad=(top=20px right=5px bottom=10px) position=topleft splitjustify=right textattrs=(size=9 weight=bold);
text x=x2a y=y1 text=text2 / backfill fillattrs=(color=white) pad=(top=20px right=350px bottom=15px)  position=topright splitjustify=left textattrs=(size=9 weight=bold);
highlow y=y1 low=x1b high=x1a /  lowcap=closedarrow lineattrs=(pattern=2 color=red);
highlow y=y1 low=x2a high=x2b /  highcap=closedarrow lineattrs=(pattern=2 color=red);

yaxis display=none colorbands=odd colorbandsattrs=(transparency=1) offsetmin=0.02 max=14.2 offsetmax=0;
x2axis display=(noline noticks novalues nolabel) labelattrs=(size=8);
xaxis values=(-2 -1 0 1 2) labelattrs=(size=8) labelattrs=(size=8) offsetmax=0 offsetmin=0;

yaxistable grp / location=inside position=left labelattrs=(size=9 weight=bold) valueattrs=(size=9 ) textgroup=id textgroupid=text indentweight=IndtWt label=' ' labelhalign=left;
yaxistable N_val / location=inside position=left labelattrs=(size=9 weight=bold) valueattrs=(size=9 ) label='N ' textgroup=id textgroupid=text labelhalign=center;
yaxistable adjmn / location=inside position=left pad=(left=15px right=15px) labelattrs=(size=9 weight=bold) textgroup=id textgroupid=text label='Adj. Mean Hgb difference (95% CI) ' labelhalign=left valueattrs=(size=9);

run;
ods pdf close;

View solution in original post

1 REPLY 1
JeffMeyers
Barite | Level 11

Here's one way to do it.  Would require some play with the padding and such if changing the file size.  I make the text with TEXT plots and then use HIGHLOW plots to make the arrows instead.  I used backfill and padding to cover up the tips of the REFLINES, but you could do highlow plots instead of REFLINE as well to make this easier.

 

For the green lines you just needed to add the MARKERCOLOR and LINECOLOR options to your attribute table.  I wasn't sure if you wanted green markers as well so you can change that if you need to.

image.png

 

data ip;
length col1 $20 grp $35 adjmn $20;
col1= 'Non-Dialysis';grp= 'Non-Dialysis';grpcd=1;catcd=1;obsid=14;
y1=13.9;text1='Favours control';x1a=-0.05;x1b=-1.5;text2='Favours TMT';x2a=0.05;x2b=1.5;
output;call missing(y1,text1,x1a,x1b,text2,x2a,x2b);
col1= 'Incident Dialysis';grp= 'Incident Dialysis';grpcd=2;catcd=2;obsid=9;Output;
col1= 'Dialysis';grp= 'Dialysis';grpcd=3;catcd=3;obsid=6;Output;

col1= 'Non-Dialysis';
grp='study001 AXXAA-ND, OL, QD'; grpcd=1;catcd=1;obsid=13;
N_val= 'TMT 1801 Control 1799';
adjmn='0.01 (-0.10,0.11)';
low=-0.1;
high=0.11 ;
mean=0.01 ;
output;

col1= 'Non-Dialysis';
grp=' study001 ESA users'; grpcd=2;catcd=1;obsid=12;
N_val= 'TMT 1001 Control 1013';
adjmn='0.28 (-0.05,0.54)';
low=-0.05;
high=0.54 ;
mean=0.28;
output;

col1= 'Non-Dialysis';
grp=' study001 ESA non-users'; grpcd=3;catcd=1;obsid=11;
N_val= 'TMT 480 Control 470';
adjmn='-0.06 (-0.17,0.26)';
low=-0.17;
high=0.26 ;
mean=-0.06;
output;


col1= 'Incident Dialysis';
grp='study002 AXXAA-ID, OL, QD'; grpcd=4;catcd=2;obsid=8;
N_val= 'TMT 1481 Control 1483';
adjmn='0.23 (-0.01,0.47)';
low=-0.01;
high=0.47;
mean=0.23;
output;


col1= 'Dialysis';
grp='study003 AXXAA-D, OL, QD'; grpcd=5;catcd=3;obsid=5;
N_val= 'TMT 1481 Control 1483';
adjmn='0.23 (-0.01,0.47)';
low=-0.01;
high=0.47;
mean=0.23;
output;


col1= 'Dialysis';
grp=' study003 HD';
N_val= 'TMT 1001 Control 1013';grpcd=6;catcd=3;obsid=4;
adjmn='0.28 (-0.05,0.54)';
low=-0.05;
high=0.54 ;
mean=0.28;
output;


col1= 'Dialysis';
grp=' study003 PD';
N_val= 'TMT 480 Control 470';grpcd=7;catcd=3;obsid=3;
adjmn='-0.06 (-0.17,0.26)';
low=-0.17;
high=0.26 ;
mean=-0.06;
output;


col1= 'Dialysis';
grp='study004 AXXAA-TD, DB, TIW'; grpcd=8;catcd=3; obsid=1;
N_val= 'TMT 204 Control 203';
adjmn='0.23 (-0.01,0.47)';
low=-0.01;
high=0.47;
mean=0.23;
output;

run;

proc sort;by catcd grpcd;run;

data ip;
set ip ;
if obsid in (1,5,6,8,9,13,14) then IndtWt=0;
else indtwt=1;

if obsid in (1,5,6,8,9,13,14 ) then id=1;
else id=2;
run;

data extra;
sid=16; low=-1.5; texta=' <------ Favours control '; high=0.5; textb=' Favours TMT ------>';output;
run;

data ip;
set ip extra;
run;

 


*** CREATE FIGURE ***;
data attrmap;
length id textweight $10 value $75. linecolor markercolor $20.;
id='text'; value='1'; textcolor='Black'; textsize=7; textweight='bold'; linecolor='black';linepattern='solid';markercolor='black';output;
id='text'; value='2'; textcolor='Green'; textsize=6; textweight='normal'; linecolor='green';linepattern='solid';markercolor='green';output;
run;
proc sort data=ip out=allnew;by catcd grpcd grp ;run;

options orientation=landscape;
ods pdf file='test.pdf' notoc bookmarkgen=no;
ods graphics / width=10in;
proc sgplot data=ip nowall noborder nocycleattrs noautolegend dattrmap=attrmap;
styleattrs axisextent=data ;
highlow y=obsid low=low high=high/ group=id highcap=serif lowcap=serif attrid=text;
scatter y=obsid x=mean / group=id markerattrs=(symbol=circlefilled size=7) attrid=text;
scatter y=obsid x=mean / markerattrs=(size=0) x2axis ;
refline 0 / axis=x lineattrs=(pattern=1);
refline 1.2 / axis=x lineattrs=(pattern=3);

text x=x1a y=y1 text=text1 / backfill fillattrs=(color=white) pad=(top=20px right=5px bottom=10px) position=topleft splitjustify=right textattrs=(size=9 weight=bold);
text x=x2a y=y1 text=text2 / backfill fillattrs=(color=white) pad=(top=20px right=350px bottom=15px)  position=topright splitjustify=left textattrs=(size=9 weight=bold);
highlow y=y1 low=x1b high=x1a /  lowcap=closedarrow lineattrs=(pattern=2 color=red);
highlow y=y1 low=x2a high=x2b /  highcap=closedarrow lineattrs=(pattern=2 color=red);

yaxis display=none colorbands=odd colorbandsattrs=(transparency=1) offsetmin=0.02 max=14.2 offsetmax=0;
x2axis display=(noline noticks novalues nolabel) labelattrs=(size=8);
xaxis values=(-2 -1 0 1 2) labelattrs=(size=8) labelattrs=(size=8) offsetmax=0 offsetmin=0;

yaxistable grp / location=inside position=left labelattrs=(size=9 weight=bold) valueattrs=(size=9 ) textgroup=id textgroupid=text indentweight=IndtWt label=' ' labelhalign=left;
yaxistable N_val / location=inside position=left labelattrs=(size=9 weight=bold) valueattrs=(size=9 ) label='N ' textgroup=id textgroupid=text labelhalign=center;
yaxistable adjmn / location=inside position=left pad=(left=15px right=15px) labelattrs=(size=9 weight=bold) textgroup=id textgroupid=text label='Adj. Mean Hgb difference (95% CI) ' labelhalign=left valueattrs=(size=9);

run;
ods pdf close;

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 968 views
  • 4 likes
  • 2 in conversation