The Expected plot is below:
I have the following code
ods path show;
ods path(prepend) work.templat(update);
ods pdf file="&g_outfile..PDF" nogtitle /*nogfootnote*/ bookmarkgen=no;
ods graphics on / reset=all width=1000px height=500px border=off ;
proc template;
define statgraph AEbyRelativeRisk;
dynamic _thk _grid;
begingraph;
layout lattice / columns=2 rowdatarange=union columngutter=1;
/*--Row block to get common external row axes--*/
rowaxes;
rowaxis / griddisplay=_grid display=(tickvalues) tickvalueattrs=(size=5);
endrowaxes;
/*--Column headers with filled background--*/
column2headers;
layout overlay;
entry " ";
endlayout;
layout overlay ;
entry "<--- Tmt1 Better Tmt2 Better --->";
endlayout;
endcolumn2headers;
/*--Left side cell with proportional values--*/
layout overlay / xaxisopts=(label="Percent" display=(ticks tickvalues label) labelattrs=(size=8) tickvalueattrs=(size=7));
referenceline y=teaex / lineattrs=(thickness=_thk) datatransparency=0.9;
scatterplot y=ae x=tmt1Pct / markerattrs=graphdata2(symbol=circlefilled size=10)
name='a' legendlabel="tmt1 (N=&NA)";
scatterplot y=ae x=tmt2Pct / markerattrs=graphdata1(symbol=trianglefilled size=10)
name='b' legendlabel="Tmt2 (N=&NB) ";
discretelegend 'a' 'b' / border=true halign=left valign=bottom valueattrs=(size=8) displayclipped=true;
endlayout;
/*--Right side cell with Relative Risk values--*/
layout overlay / xaxisopts=(label="Relative Risk with 0.95 CI (*ESC*){unicode '000a'x} tmt1 vs tmt2"
labelattrs=(size=8) tickvalueattrs=(size=7));
referenceline y=teaex / lineattrs=(thickness=_thk) datatransparency=0.9;
scatterplot y=ae x=RelRisk / xerrorlower=LowerCL xerrorupper=UpperCL
markerattrs=(symbol=circlefilled size=10);
referenceline x=1 / lineattrs=graphdatadefault (pattern=solid color=grey);
endlayout;
endlayout;
endgraph;
end;
run;
ods graphics / reset width=6in height=4in imagename='AEbyRelativeRisk';
proc sgrender data=ip template=AEbyRelativeRisk;
dynamic _thk='0' _grid='on';
run;
ods pdf close;
The figure I get is as below:
The issues are:
1) how to split each of the y axis tick values into two or more lines.
2) the figure looks very pale ,how to improve the texts and lines to be a bit more bold or darker so that it will be readable.
On the ROWAXIS statement, use DISCRETEOPTS=(TICKVALUEFITPOLICY=SPLIT). The tick value will be split if it does not fit. You can reduce the width of the cell.
Else, use DISCRETEOPTS=(TICKVALUEFITPOLICY=SPLITALWAYS) and specify the Split character.
Overall, you can reduce the graph size and increase the DPI=200 or higher. This will scale up the fonts. You can also set bigger fonts for the tick values and other texts in the graph.
ods graphics on / reset=all width=6in height=3in border=off ;
ods pdf dpi=300;
See examples:
https://blogs.sas.com/content/graphicallyspeaking/2015/10/31/adverse-events-graph-with-nnt/
https://blogs.sas.com/content/graphicallyspeaking/2017/11/08/long-category-values/
On the ROWAXIS statement, use DISCRETEOPTS=(TICKVALUEFITPOLICY=SPLIT). The tick value will be split if it does not fit. You can reduce the width of the cell.
Else, use DISCRETEOPTS=(TICKVALUEFITPOLICY=SPLITALWAYS) and specify the Split character.
Overall, you can reduce the graph size and increase the DPI=200 or higher. This will scale up the fonts. You can also set bigger fonts for the tick values and other texts in the graph.
ods graphics on / reset=all width=6in height=3in border=off ;
ods pdf dpi=300;
See examples:
https://blogs.sas.com/content/graphicallyspeaking/2015/10/31/adverse-events-graph-with-nnt/
https://blogs.sas.com/content/graphicallyspeaking/2017/11/08/long-category-values/
One more issue:
How to display the xaxis for the right panel as 0.25, 0.50 1 2 4 8 ? my code below. This gives 0.25 1 then 4 only
You can try using the TICKVALUEFITPOLICY=NONE for XAXISOPTS. This will avoid thinning of values due to collision of tick values. Not sure why you need TICKDISPLAYLIST.
Do you get all the values if you remove 0.25 and 0.5 from the list? These values may be causing some values to be dropped. You can also increase the relative width of the right cell.
Hi
the issue here is I need to present the x axis on a scale using powers of 2 (..., 1/4, 1/2, 1, 2, 4, ...) for the purpose of fitting a larger range of relative risk values, while also keeping the reference line of 1 closer to the center of the panel. This is the requirement and im unable to do this using tickvaluelist and policy.
Some such graphs have used a log scale on the x-axis to get the result you need.
Please see page 14 of this paper. The xaxisopts for the 2nd cell uses a TYPE of log .
https://www.mwsug.org/proceedings/2014/SS/MWSUG-2014-SS07.pdf
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.