<?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 Re: Why is SAS changing the colors for a variable in vbar plots in proc sgplot? in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Why-is-SAS-changing-the-colors-for-a-variable-in-vbar-plots-in/m-p/157165#M5891</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Group colors are assigned based on the ORDER in which the group values are encountered in the data.&amp;nbsp; If you want consistent group colors, you can use the Discrete Attributes Map Feature, where you can specify which group VALUE" gets which color.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Feb 2015 19:39:34 GMT</pubDate>
    <dc:creator>Jay54</dc:creator>
    <dc:date>2015-02-06T19:39:34Z</dc:date>
    <item>
      <title>Why is SAS changing the colors for a variable in vbar plots in proc sgplot?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Why-is-SAS-changing-the-colors-for-a-variable-in-vbar-plots-in/m-p/157164#M5890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I'm using SAS 9.3. I have a dataset with several hundred readings. I am attempting to plot two variables relative to a third, using proc sgplot. The first two values, which I will call VarA and VarB, are continuous and have values between 1 and 5. The third variable, XValue, contains only integer values from 1 through 5 inclusive. I am using proc sgplot to print vertical bar charts for the frequency of each&amp;nbsp; For some reason which I cannot figure out, the colors for the bar charts are different for the two plots. I've attached a file showing the output, where you can see that the color order for the plots is as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XValue&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VarA&amp;nbsp;&amp;nbsp;&amp;nbsp; VarB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; green&amp;nbsp;&amp;nbsp; green&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; blue&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brown&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; red&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; blue&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brown&amp;nbsp;&amp;nbsp; red&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; purple&amp;nbsp;&amp;nbsp; purple&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In other words, while the end colors are consistent, the colors for the intermediate values are not. I would like the plots to maintain consistent colors. The code I am using follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;value grpf&lt;/P&gt;&lt;P&gt; 1 - &amp;lt;1.5 = "1 - 1.5"&lt;/P&gt;&lt;P&gt; 1.5 - &amp;lt;2.5 = "1.5 - 2.5"&lt;/P&gt;&lt;P&gt;&amp;nbsp; 2.5 - &amp;lt;3.5 = "2.5 - 3.5"&lt;/P&gt;&lt;P&gt; 3.5 - &amp;lt;4.5 = "3.5 - 4.5"&lt;/P&gt;&lt;P&gt; 4.5 - 5 = "4.5 - 5";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;value xvalf&lt;/P&gt;&lt;P&gt; 1 = "Why"&lt;/P&gt;&lt;P&gt; 2 = "are"&lt;/P&gt;&lt;P&gt; 3 = "these"&lt;/P&gt;&lt;P&gt; 4 = "different"&lt;/P&gt;&lt;P&gt; 5 = "colors?";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sgplot data=use;&lt;/P&gt;&lt;P&gt; title "Why is SAS changing the order of the colors for XValue?";&lt;/P&gt;&lt;P&gt; vbar VarA / stat=freq group=XValue grouporder=ascending groupdisplay=cluster;&lt;/P&gt;&lt;P&gt; format VarA VarB grpf. XValue xvalf.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sgplot data=use;&lt;/P&gt;&lt;P&gt; title "Why is SAS changing the order of the colors for XValue?";&lt;/P&gt;&lt;P&gt; vbar VarB / stat=freq group=XValue grouporder=ascending groupdisplay=cluster;&lt;/P&gt;&lt;P&gt; format VarA VarB grpf. XValue xvalf.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And the resulting plots are:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="SGPlot30.png" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/9064_SGPlot30.png" width="450" /&gt;&lt;IMG alt="SGPlot32.png" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/9065_SGPlot32.png" width="450" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you can see, the only difference between the two instances of proc sgplot is the variable being plotted by the vbar statement. How can I obtain consistent colors for multiple plots?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is a simplified form of the program. I have many more plots I need to run, and I need the color of XValue to be consistent across all the plots. I'd appreciate any help anyone can give me.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Feb 2015 19:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Why-is-SAS-changing-the-colors-for-a-variable-in-vbar-plots-in/m-p/157164#M5890</guid>
      <dc:creator>RobinDC</dc:creator>
      <dc:date>2015-02-06T19:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why is SAS changing the colors for a variable in vbar plots in proc sgplot?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Why-is-SAS-changing-the-colors-for-a-variable-in-vbar-plots-in/m-p/157165#M5891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Group colors are assigned based on the ORDER in which the group values are encountered in the data.&amp;nbsp; If you want consistent group colors, you can use the Discrete Attributes Map Feature, where you can specify which group VALUE" gets which color.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Feb 2015 19:39:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Why-is-SAS-changing-the-colors-for-a-variable-in-vbar-plots-in/m-p/157165#M5891</guid>
      <dc:creator>Jay54</dc:creator>
      <dc:date>2015-02-06T19:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why is SAS changing the colors for a variable in vbar plots in proc sgplot?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Why-is-SAS-changing-the-colors-for-a-variable-in-vbar-plots-in/m-p/157166#M5892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sanjay, the group variable is identical in both plots. The dataset is identical, I am not sorting or changing it in any way between the two instances of proc sgplot. If I understand what you have said correctly, and&amp;nbsp; if I have not changed the order of the data, then the order of the colors should not be changing. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Feb 2015 19:51:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Why-is-SAS-changing-the-colors-for-a-variable-in-vbar-plots-in/m-p/157166#M5892</guid>
      <dc:creator>RobinDC</dc:creator>
      <dc:date>2015-02-06T19:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: Why is SAS changing the colors for a variable in vbar plots in proc sgplot?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Why-is-SAS-changing-the-colors-for-a-variable-in-vbar-plots-in/m-p/157167#M5893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's because the data order is different between varA and varB. The colors are assigned to the group values in the order that they come in. We have a nice feature in the SG procedures to assign attributes directly to group values so that they always look the same regardless of ordering. It's called an "attributes map". Think of it as a format for visual attributes :-). The attrmap must contain the *formatted* value for comparison. See the doc for more details. In the meantime, try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data attrmap;&lt;/P&gt;&lt;P&gt;retain id "myid";&lt;/P&gt;&lt;P&gt;length value $ 9 fillstyle $ 10;&lt;/P&gt;&lt;P&gt;input value $ fillstyle $;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Why&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphdata1&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;are&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphdata2&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;these&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphdata3&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;different&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphdata4&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;colors?&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphdata5&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sgplot data=use dattrmap=attrmap;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;title "Why is SAS changing the order of the colors for XValue?";&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;vbar VarA / stat=freq group=XValue grouporder=ascending groupdisplay=cluster attrid=myid;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;format VarA VarB grpf. XValue xvalf.;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sgplot data=use dattrmap=attrmap;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;title "Why is SAS changing the order of the colors for XValue?";&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;vbar VarB / stat=freq group=XValue grouporder=ascending groupdisplay=cluster &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; attrid=myid&lt;/SPAN&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;format VarA VarB grpf. XValue xvalf.;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Feb 2015 19:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Why-is-SAS-changing-the-colors-for-a-variable-in-vbar-plots-in/m-p/157167#M5893</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2015-02-06T19:58:57Z</dc:date>
    </item>
  </channel>
</rss>

