I want to display the fit statistics for each CHMI group in the same colors that correspond with the plotted data points and regression lines. I.e., I want fit1 to be blue, fit2 to be gold, fit3 to be gray, and fit4 to be red. Is there a way to get individual colors for each line of text? I tried multiple inset lines but ended up with the text overlapping each other.
/*Get R- and p-value*/
ods exclude all;
proc sort data= _cpcr_; by aperiodc; run;
proc glm data= _cpcr_;
by aperiodc;
*class aperiodc;
model max_temp = aval;
ods output ModelANOVA= anova FitStatistics= fit;
run;
ods select all;
data _tmp_;
merge fit anova(where= (HypothesisType= 3));
by aperiodc;
fit= "R="||put(sqrt(RSquare), 5.3)||", p="||put(ProbF, 5.3);
data _null_;
set _tmp_;
if aperiodc = 'CHMI 1' then call symput('fit1', strip(fit));
else if aperiodc = 'CHMI 2' then call symput('fit2', strip(fit));
else if aperiodc = 'CHMI 3' then call symput('fit3', strip(fit));
else if aperiodc = 'CHMI 4' then call symput('fit4', strip(fit));
run;
%put &=fit1 &=fit2 &=fit3 &=fit4;
/*Plot Data*/
ods graphics on / attrpriority= none;
proc sgplot data= _cpcr_;
styleattrs datacolors= (blue gold gray red)
datacontrastcolors= (blue gold gray red)
datasymbols= (asterisk circle plus star)
datalinepatterns= (solid mediumdash dashdotdot shortdashdot);
reg y= max_temp x= aval / group= aperiodc clm clmtransparency= 0.8;
xaxis label= "Maximum Parasite Density" grid;
yaxis label= "Oral Temperature" grid;
keylegend / title= "CHMI";
inset ("R="="&fit1"
"R="="&fit2"
"R="="&fit3"
"R="="&fit4")/ position= bottomright;
run;
The best way to do this is to use legend items to build your own "text" legend. Here is a simple example:
proc sgplot data=sashelp.class;
vbar age / group=sex groupdisplay=cluster;
legenditem name="line1" type=text / text="R=" label="0.5" textattrs=(color=red) labelattrs=(color=red);
legenditem name="line2" type=text / text="R=" label="0.8" textattrs=(color=blue) labelattrs=(color=blue);
keylegend "line1" "line2" / location=inside across=1;
run;
The best way to do this is to use legend items to build your own "text" legend. Here is a simple example:
proc sgplot data=sashelp.class;
vbar age / group=sex groupdisplay=cluster;
legenditem name="line1" type=text / text="R=" label="0.5" textattrs=(color=red) labelattrs=(color=red);
legenditem name="line2" type=text / text="R=" label="0.8" textattrs=(color=blue) labelattrs=(color=blue);
keylegend "line1" "line2" / location=inside across=1;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.