<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Specify specific colors for text in PROC SGPLOT in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Specify-specific-colors-for-text-in-PROC-SGPLOT/m-p/799435#M22651</link>
    <description>&lt;P&gt;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.&amp;nbsp;&lt;EM&gt;I.e.,&lt;/EM&gt; 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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*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 &amp;amp;=fit1 &amp;amp;=fit2 &amp;amp;=fit3 &amp;amp;=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="="&amp;amp;fit1" 
			"R="="&amp;amp;fit2" 
			"R="="&amp;amp;fit3"
			"R="="&amp;amp;fit4")/ position= bottomright;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Mar 2022 19:42:16 GMT</pubDate>
    <dc:creator>mariko5797</dc:creator>
    <dc:date>2022-03-01T19:42:16Z</dc:date>
    <item>
      <title>Specify specific colors for text in PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Specify-specific-colors-for-text-in-PROC-SGPLOT/m-p/799435#M22651</link>
      <description>&lt;P&gt;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.&amp;nbsp;&lt;EM&gt;I.e.,&lt;/EM&gt; 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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*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 &amp;amp;=fit1 &amp;amp;=fit2 &amp;amp;=fit3 &amp;amp;=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="="&amp;amp;fit1" 
			"R="="&amp;amp;fit2" 
			"R="="&amp;amp;fit3"
			"R="="&amp;amp;fit4")/ position= bottomright;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 19:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Specify-specific-colors-for-text-in-PROC-SGPLOT/m-p/799435#M22651</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2022-03-01T19:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Specify specific colors for text in PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Specify-specific-colors-for-text-in-PROC-SGPLOT/m-p/799445#M22652</link>
      <description>&lt;P&gt;The best way to do this is to use legend items to build your own "text" legend. Here is a simple example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 20:27:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Specify-specific-colors-for-text-in-PROC-SGPLOT/m-p/799445#M22652</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2022-03-01T20:27:05Z</dc:date>
    </item>
  </channel>
</rss>

