05-18-2016 07:55 PM
I am new to PROC TEMPLATE but I would like to create a scatterplot with regression lines overlayed. I have a categorical variable "comp" that has 3 values. I would like there to be 3 regression lines, one for each of these groups. Similarly, I would like the scatterplot to have different shapes and colors for each of the "comp" values.
When I run the code below, I get only 2 regression lines. Where am I going wrong? I am using SAS 9.3, and a sample of the data is attached to this message:
proc template; define style Styles.BAPstyle; parent=styles.listing; style GraphData1 from GraphData1 / ContrastColor=blue Color=blue MarkerSymbol="CircleFilled" Linestyle=1; style GraphData2 from GraphData2 / ContrastColor=orange Color=orange MarkerSymbol="TriangleFilled" Linestyle=2; style GraphData3 from GraphData3 / ContrastColor=black Color=black MarkerSymbol="SquareFilled" Linestyle=3; end; run; proc template; define statgraph BAP; begingraph ; entrytitle "Sector 1 Bland-Altman Plot"; layout overlay / yaxisopts=(label="Difference between Measurements") xaxisopts = (label = "Measurement Average"); scatterplot x = mean y = diff / group = comp name = "diff"; regressionplot x=mean y=diff / group=comp name="trends"; discretelegend "trends" "diff"/ title="Comparisons"; referenceline Y = 0 / CURVELABEL = "Zero Bias Line" CURVELABELLOCATION = Outside DATATRANSPARENCY = 0.5; referenceline Y = &upper / CURVELABEL = "95% Upper Limit" CURVELABELLOCATION = Outside DATATRANSPARENCY = 0.5; referenceline Y = &lower / CURVELABEL = "95% Lower Limit" CURVELABELLOCATION = Outside DATATRANSPARENCY = 0.5; endlayout; endgraph; end; run; proc sort data = test; by comp; run; ods _all_ close; ods graphics / reset imagename="Bland-Altman"; ods pdf file="&out.\fig1.pdf" style=BAPstyle; proc sgrender data=test template=BAP; format comp $comp.; run; ods pdf close; ods pdf;
Here is the plot that I get in return (notice the missing black line):
Additionally, I would love suggestions on how to make a legend that grouped the scatterplot point with the corresponding line with the relevant label.
Thank you in advance!
05-18-2016 11:01 PM
I think the third line is behind the blue line. To test this theory, change the REGRESSIONPLOT to LOESSPLOT and see if the line appears.
As for the legend, The labels will come from the group values, as the plots are grouped plots. Also, instead of DISCRETELEGEND, use MERGEDLEGEND with the names of the SCATTERPLOT and REGRESSIONPLOT. For example,
MERGEDLEGEND "trends" "diff" / title="Comparisons";
Hope this helps!
05-23-2016 04:17 PM
Thanks for the suggestions, DanH_sas, but changing to LOESSPLOT does not make a third line appear. I have isolated the problem to the format statement. For some reason without the format I get exactly what I want, 3 regression lines. Can anyone tell me why the format statement is not compatable here?