BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mariko5797
Pyrite | Level 9

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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;

 

 

View solution in original post

1 REPLY 1
DanH_sas
SAS Super FREQ

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;

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 581 views
  • 5 likes
  • 2 in conversation