I am using proc template with layout lattice to create 2 side by side ROC figures, each figure having several overlayed lines. The problem I am having is that the same legend is placed under each figure - which is ok for identifying the different groups, except that the legend text also includes the AUC value, which of course will be different depending on the figure. In short, can someone refer me to a reference on how to create a custom legend? I'm using 9.2.
Thanks.
Hi,
Custom legend support is available in SAS 9.3 via the LEGENDITEM statement in the Graph Template Language.
Can you point to an example output and/or template code to see if we can suggest a solution for SAS 9.2 ?
With Regards,
-Prashant.
Template code looks like this:
define statgraph Graphics.ROCOverlay;
notes "Receiver Operating Characteristic Overlaid Curves";
dynamic _TITLE1 ;
BeginGraph;
entrytitle _TITLE1;
layout lattice / columns=2 columngutter=0 columnweights=(0.5 0.5) ;
layout overlayequated /
equatetype = square
yaxisopts = (gridDisplay=off label="Sensitivity" shortlabel = "TPR" offsetmin=0.05 offsetmax=0.05)
xaxisopts = (gridDisplay=off label="1 - Specificity" shortlabel="FPR" offsetmin=0.05 offsetmax=0.05)
commonaxisopts = ( tickvaluelist=(0 .25 .5 .75 1) viewmin = 0 viewmax = 1)
;
/* Trt1 Curves */
entry halign=center "Trt 1"/location=outside valign=TOP;
lineparm x=0 y=0 slope=1 /
extend = true
lineattrs =( color = grey thickness = 1.5px)
;
seriesplot y =_SENSIT_ x=_1MSPEC_ /
connectorder = xaxis
tip = (group y x)
group = _ROC_
index = _GROUP_
name = "Step"
primary = true
lineattrs = (thickness = 1px)
;
/* Legend Defn */
discretelegend "Step" / Title = "ROC Curve (Area)"
LOCATION = /*INSIDE*/ outside
HALIGN = /*RIGHT*/ Left
VALIGN = BOTTOM
PAD = (RIGHT = 2PX bottom = 2px)
ORDER = ROWMAJOR
ACROSS = 1
BORDER = FALSE
TITLEATTRS = (family = 'times' size = 8pt weight = BOLD)
VALUEATTRS = (family = 'times' size = 7pt);
;
endLayout;
/* Placebo Curves */
layOut overLayEquated /
equatetype = square
yaxisopts = (gridDisplay=off label="Sensitivity" shortlabel = "TPR" offsetmin=0.05 offsetmax=0.05)
xaxisopts = (gridDisplay=off label="1 - Specificity" shortlabel="FPR" offsetmin=0.05 offsetmax=0.05)
commonaxisopts = ( tickvaluelist=(0 .25 .5 .75 1) viewmin = 0 viewmax = 1)
;
entry halign=center "Placebo"/location=outside valign=TOP;
lineparm x=0 y=0 slope=1 /
extend = true
lineattrs =( color = grey thickness = 1.5px)
;
seriesplot y =pbo_SENSIT x=pbo_1MSPEC /
connectorder = xaxis
tip = (group y x)
group = pbo_ROC
index = pbo_GROUP
name = "Step"
primary = true
lineattrs = (thickness = 1px)
;
discretelegend "Step" / Title = "ROC Curve (Area)"
LOCATION = /*INSIDE*/ outside
HALIGN = /*RIGHT*/ Left
VALIGN = BOTTOM
PAD = (RIGHT = 2PX bottom = 2px)
ORDER = ROWMAJOR
ACROSS = 1
BORDER = FALSE
TITLEATTRS = (family = 'times' size = 8pt weight = BOLD)
VALUEATTRS = (family = 'times' size = 7pt);
;
endlayout;
endLayout;
EndGraph;
end;
run;
The problem is that both of your plots have the same name ("Step"). Change their names to be unique (e.g. "Step1" and "Step2"), and change the corresponding names in the DISCRETELEGEND statements. That should give you your unique legends.
Hope this helps!
Dan
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.