<?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 Annotating boxplot to change bar colors (sgplot) in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Annotating-boxplot-to-change-bar-colors-sgplot/m-p/848333#M23351</link>
    <description>&lt;P&gt;I want to annotate a boxplot to have some bars in one color and some in another. I try with the code below but it's not working. Why? What I want is to have last two bars (for year &amp;gt; 2018) red, while all other green&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Sample dataset*/
data test;
	call streaminit(123);
	do year= 2010 to 2020;
		do i = 1 to 100;
			year = year;
			var1 = RAND('UNIForm', 30, 100);
		output;
		end;
	end;
run;

/* Create groups based on year*/
data test;
	set test;
	group = (year &amp;gt; 2018);
run;

/* Specify colors*/
data my_colors;
	input id $ value fillcolor $;
	datalines;
	myid 0 CX96ceb4
	myid 1 CXff6f69
	;
run;

/* Annotated box plot*/	
proc sgplot data = test dattrmap=my_colors;
	vbox var1/ category = year nooutliers nomean attrid = myid;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When I try to set colors "by hand" for all bars, it works OK:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data = test;
	vbox var1/ category = year nooutliers nomean fillattrs=(color = "CX96ceb4");
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Dec 2022 13:33:47 GMT</pubDate>
    <dc:creator>chris2377</dc:creator>
    <dc:date>2022-12-07T13:33:47Z</dc:date>
    <item>
      <title>Annotating boxplot to change bar colors (sgplot)</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Annotating-boxplot-to-change-bar-colors-sgplot/m-p/848333#M23351</link>
      <description>&lt;P&gt;I want to annotate a boxplot to have some bars in one color and some in another. I try with the code below but it's not working. Why? What I want is to have last two bars (for year &amp;gt; 2018) red, while all other green&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Sample dataset*/
data test;
	call streaminit(123);
	do year= 2010 to 2020;
		do i = 1 to 100;
			year = year;
			var1 = RAND('UNIForm', 30, 100);
		output;
		end;
	end;
run;

/* Create groups based on year*/
data test;
	set test;
	group = (year &amp;gt; 2018);
run;

/* Specify colors*/
data my_colors;
	input id $ value fillcolor $;
	datalines;
	myid 0 CX96ceb4
	myid 1 CXff6f69
	;
run;

/* Annotated box plot*/	
proc sgplot data = test dattrmap=my_colors;
	vbox var1/ category = year nooutliers nomean attrid = myid;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When I try to set colors "by hand" for all bars, it works OK:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data = test;
	vbox var1/ category = year nooutliers nomean fillattrs=(color = "CX96ceb4");
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 13:33:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Annotating-boxplot-to-change-bar-colors-sgplot/m-p/848333#M23351</guid>
      <dc:creator>chris2377</dc:creator>
      <dc:date>2022-12-07T13:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Annotating boxplot to change bar colors (sgplot)</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Annotating-boxplot-to-change-bar-colors-sgplot/m-p/848337#M23352</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24842"&gt;@chris2377&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n1waawwbez01ppn15dn9ehmxzihf.htm#n0ihz5mnsij0ern0zx0ildin6aehk" target="_blank" rel="noopener"&gt;GROUP= option&lt;/A&gt; to tell SAS that the values 0, 1 in the attribute map dataset refer to variable &lt;FONT face="courier new,courier"&gt;group&lt;/FONT&gt; of dataset TEST:&lt;/P&gt;
&lt;PRE&gt;vbox var1/ category = year &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;group = group&lt;/FONT&gt;&lt;/STRONG&gt; nooutliers nomean attrid = myid;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Dec 2022 13:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Annotating-boxplot-to-change-bar-colors-sgplot/m-p/848337#M23352</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-12-07T13:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: Annotating boxplot to change bar colors (sgplot)</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Annotating-boxplot-to-change-bar-colors-sgplot/m-p/848342#M23353</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As simple as that. I simply forgot the group argument. Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 13:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Annotating-boxplot-to-change-bar-colors-sgplot/m-p/848342#M23353</guid>
      <dc:creator>chris2377</dc:creator>
      <dc:date>2022-12-07T13:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Annotating boxplot to change bar colors (sgplot)</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Annotating-boxplot-to-change-bar-colors-sgplot/m-p/848346#M23354</link>
      <description>&lt;P&gt;You're missing the GROUP=group on the VBOX statement needed to look up the values in the attrmap. I also had to retype the "myid" values in the attrmap, as it appeared to have hidden characters that caused a mismatch. But, that could have been a cut-and-paste artifact.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;
&lt;P&gt;Dan&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 14:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Annotating-boxplot-to-change-bar-colors-sgplot/m-p/848346#M23354</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2022-12-07T14:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Annotating boxplot to change bar colors (sgplot)</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Annotating-boxplot-to-change-bar-colors-sgplot/m-p/848347#M23355</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15130"&gt;@DanH_sas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your reply. After adding "group" option everything works as expected, so it may be the copy-paste issue.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 14:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Annotating-boxplot-to-change-bar-colors-sgplot/m-p/848347#M23355</guid>
      <dc:creator>chris2377</dc:creator>
      <dc:date>2022-12-07T14:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Annotating boxplot to change bar colors (sgplot)</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Annotating-boxplot-to-change-bar-colors-sgplot/m-p/848353#M23356</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15130"&gt;@DanH_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I also had to retype the "myid" values in the attrmap, as it appeared to have hidden characters that caused a mismatch.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Indeed, the indentation of that data step was achieved by a leading tab character. I hadn't even noticed these tabs as the Enhanced Editor (unlike the SAS Studio interface, I think) treats them as blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24842"&gt;@chris2377&lt;/a&gt;: It's better to avoid tab characters in SAS code. There are option settings like "Insert spaces for tabs" available both in the Enhanced Editor and in SAS Studio to create a specified number of space characters when you press the Tab key.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 14:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Annotating-boxplot-to-change-bar-colors-sgplot/m-p/848353#M23356</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-12-07T14:33:37Z</dc:date>
    </item>
  </channel>
</rss>

