<?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 proc sgplot stacked vbar colors in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/proc-sgplot-stacked-vbar-colors/m-p/11109#M153</link>
    <description>I have an SGPlot statement which shows the sentiment (var: sentiment_category - values: Postive, Negative, Neutral) per category (var: category - values: service, price, product,..)&lt;BR /&gt;
&lt;BR /&gt;
proc sgplot data = graph_final;&lt;BR /&gt;
      vbar category / freq=count group=sentiment_category  NOSTATLABEL /*datalabel*/;&lt;BR /&gt;
      xaxis       label=" "  discreteorder=data;&lt;BR /&gt;
      yaxis       label=" "  GRID ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
To align the colors with the sentiment (green=positive, yellow=neutral and red=negative) I’ve modified the style as following:&lt;BR /&gt;
&lt;BR /&gt;
proc template;&lt;BR /&gt;
Define style styles.mystyle;&lt;BR /&gt;
  Parent=styles.&amp;amp;styleclass.;&lt;BR /&gt;
  Style graphdata1 from graphdata1 / contrastcolor=grey color=CX84AF5B; /* green */&lt;BR /&gt;
  Style graphdata2 from graphdata2 / contrastcolor=grey color=CXF1DC63; /* yellow */&lt;BR /&gt;
  Style graphdata3 from graphdata3 / contrastcolor=grey color=CXC95A49; /* red */&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
This works if for the first category there are no zeroes for sentiment_category:&lt;BR /&gt;
&lt;BR /&gt;
category;sentiment_category;COUNT;percent;graph_order&lt;BR /&gt;
Car;Positive;3;10;1&lt;BR /&gt;
Car;Neutral;1;3;2&lt;BR /&gt;
Car;Negative;26;87;3&lt;BR /&gt;
General;Positive;12;60;1&lt;BR /&gt;
General;Neutral;0;0;2&lt;BR /&gt;
General;Negative;8;40;3&lt;BR /&gt;
Price;Positive;1;33;1&lt;BR /&gt;
Price;Neutral;0;0;2&lt;BR /&gt;
Price;Negative;2;67;3&lt;BR /&gt;
Service;Positive;24;67;1&lt;BR /&gt;
Service;Neutral;0;0;2&lt;BR /&gt;
Service;Negative;12;33;3&lt;BR /&gt;
&lt;BR /&gt;
In this case, everything is how I want it to be. But suppose that the “neutral” for Car is 0, then the colors are no longer aligned with the sentiment. I understand the colors are assigned based on the order of appearance and if the value for a sentiment_category is 0 then it is not taken into account.&lt;BR /&gt;
&lt;BR /&gt;
How can I make sure that the colors are always aligned with the sentiment?&lt;BR /&gt;
&lt;BR /&gt;
One suggestion I've had is to make the proc template definition variable, based on the actual order in the dataset (e.g. if the first non-blank value is Negative, than the first color is red) which does align the colors with the sentiment but.. I also want to make sure that within the stacked bar the positive sentiment is on the bottom, the neutral sentiment in the middle and the negative sentiment on top. Continuing with the same example (suppose that the "neutral" for Car is 0), the stacked bar for the category "car" consists of positive (green) and negative (red). For the second category (General) the order within the stack is positive, negative and neutral. The colors are aligned with the sentiment but the order within the stack needs to be positive, neutral and negative.&lt;BR /&gt;
&lt;BR /&gt;
PS: if my explanation isn't clear enough or if I need to include a working example, please let me know.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Cedric</description>
    <pubDate>Fri, 10 Jun 2011 17:37:33 GMT</pubDate>
    <dc:creator>CColpaert</dc:creator>
    <dc:date>2011-06-10T17:37:33Z</dc:date>
    <item>
      <title>proc sgplot stacked vbar colors</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/proc-sgplot-stacked-vbar-colors/m-p/11109#M153</link>
      <description>I have an SGPlot statement which shows the sentiment (var: sentiment_category - values: Postive, Negative, Neutral) per category (var: category - values: service, price, product,..)&lt;BR /&gt;
&lt;BR /&gt;
proc sgplot data = graph_final;&lt;BR /&gt;
      vbar category / freq=count group=sentiment_category  NOSTATLABEL /*datalabel*/;&lt;BR /&gt;
      xaxis       label=" "  discreteorder=data;&lt;BR /&gt;
      yaxis       label=" "  GRID ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
To align the colors with the sentiment (green=positive, yellow=neutral and red=negative) I’ve modified the style as following:&lt;BR /&gt;
&lt;BR /&gt;
proc template;&lt;BR /&gt;
Define style styles.mystyle;&lt;BR /&gt;
  Parent=styles.&amp;amp;styleclass.;&lt;BR /&gt;
  Style graphdata1 from graphdata1 / contrastcolor=grey color=CX84AF5B; /* green */&lt;BR /&gt;
  Style graphdata2 from graphdata2 / contrastcolor=grey color=CXF1DC63; /* yellow */&lt;BR /&gt;
  Style graphdata3 from graphdata3 / contrastcolor=grey color=CXC95A49; /* red */&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
This works if for the first category there are no zeroes for sentiment_category:&lt;BR /&gt;
&lt;BR /&gt;
category;sentiment_category;COUNT;percent;graph_order&lt;BR /&gt;
Car;Positive;3;10;1&lt;BR /&gt;
Car;Neutral;1;3;2&lt;BR /&gt;
Car;Negative;26;87;3&lt;BR /&gt;
General;Positive;12;60;1&lt;BR /&gt;
General;Neutral;0;0;2&lt;BR /&gt;
General;Negative;8;40;3&lt;BR /&gt;
Price;Positive;1;33;1&lt;BR /&gt;
Price;Neutral;0;0;2&lt;BR /&gt;
Price;Negative;2;67;3&lt;BR /&gt;
Service;Positive;24;67;1&lt;BR /&gt;
Service;Neutral;0;0;2&lt;BR /&gt;
Service;Negative;12;33;3&lt;BR /&gt;
&lt;BR /&gt;
In this case, everything is how I want it to be. But suppose that the “neutral” for Car is 0, then the colors are no longer aligned with the sentiment. I understand the colors are assigned based on the order of appearance and if the value for a sentiment_category is 0 then it is not taken into account.&lt;BR /&gt;
&lt;BR /&gt;
How can I make sure that the colors are always aligned with the sentiment?&lt;BR /&gt;
&lt;BR /&gt;
One suggestion I've had is to make the proc template definition variable, based on the actual order in the dataset (e.g. if the first non-blank value is Negative, than the first color is red) which does align the colors with the sentiment but.. I also want to make sure that within the stacked bar the positive sentiment is on the bottom, the neutral sentiment in the middle and the negative sentiment on top. Continuing with the same example (suppose that the "neutral" for Car is 0), the stacked bar for the category "car" consists of positive (green) and negative (red). For the second category (General) the order within the stack is positive, negative and neutral. The colors are aligned with the sentiment but the order within the stack needs to be positive, neutral and negative.&lt;BR /&gt;
&lt;BR /&gt;
PS: if my explanation isn't clear enough or if I need to include a working example, please let me know.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Cedric</description>
      <pubDate>Fri, 10 Jun 2011 17:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/proc-sgplot-stacked-vbar-colors/m-p/11109#M153</guid>
      <dc:creator>CColpaert</dc:creator>
      <dc:date>2011-06-10T17:37:33Z</dc:date>
    </item>
    <item>
      <title>proc sgplot stacked vbar colors</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/proc-sgplot-stacked-vbar-colors/m-p/11110#M154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In SAS 9.3, you will easily be able to associate visual attributes with data values in what's called an "attribute map". In the meantime, you can use an INDEX in GTL to create the linkage. The following program should get you what you want. Let me know if you have any questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;proc template;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Define style styles.mystyle;&lt;/P&gt;&lt;P&gt;Parent=styles.listing;&lt;/P&gt;&lt;P&gt;Style graphdata1 from graphdata1 / contrastcolor=grey color=CX84AF5B; /* green */&lt;/P&gt;&lt;P&gt;Style graphdata2 from graphdata2 / contrastcolor=grey color=CXF1DC63; /* yellow */&lt;/P&gt;&lt;P&gt;Style graphdata3 from graphdata3 / contrastcolor=grey color=CXC95A49; /* red */&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN lang="EN"&gt;﻿&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;data sentiment;&lt;/P&gt;&lt;P&gt;input category $ sentiment_category $ COUNT percent graph_order;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;Car Positive 3 10 1&lt;/P&gt;&lt;P&gt;Car Neutral 1 3 2&lt;/P&gt;&lt;P&gt;Car Negative 26 87 3&lt;/P&gt;&lt;P&gt;General Positive 12 60 1&lt;/P&gt;&lt;P&gt;General Neutral 0 0 2&lt;/P&gt;&lt;P&gt;General Negative 8 40 3&lt;/P&gt;&lt;P&gt;Price Positive 1 33 1&lt;/P&gt;&lt;P&gt;Price Neutral 0 0 2&lt;/P&gt;&lt;P&gt;Price Negative 2 67 3&lt;/P&gt;&lt;P&gt;Service Positive 24 67 1&lt;/P&gt;&lt;P&gt;Service Neutral 0 0 2&lt;/P&gt;&lt;P&gt;Service Negative 12 33 3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN lang="EN"&gt;﻿&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;data indexed;&lt;/P&gt;&lt;P&gt;set sentiment;&lt;/P&gt;&lt;P&gt;if (sentiment_category eq "Positive") then index=1;&lt;/P&gt;&lt;P&gt;if (sentiment_category eq "Neutral") then index=2;&lt;/P&gt;&lt;P&gt;if (sentiment_category eq "Negative") then index=3;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN lang="EN"&gt;﻿&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;proc template;&lt;/P&gt;&lt;P&gt;define statgraph barchart;&lt;/P&gt;&lt;P&gt;begingraph;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; layout overlay / xaxisopts=( Label=" " ) yaxisopts=( griddisplay=on Label=" " linearopts=(Integer=true));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BarChart X=category Y=Count / Group=sentiment_category index=index NAME="VBAR";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DiscreteLegend "VBAR"/ title="sentiment_category";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; endlayout;&lt;/P&gt;&lt;P&gt;endgraph;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN lang="EN"&gt;﻿&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;ods listing style=mystyle;&lt;/P&gt;&lt;P&gt;proc sgrender data=indexed template=barchart; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Jun 2011 15:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/proc-sgplot-stacked-vbar-colors/m-p/11110#M154</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2011-06-23T15:02:42Z</dc:date>
    </item>
    <item>
      <title>proc sgplot stacked vbar colors</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/proc-sgplot-stacked-vbar-colors/m-p/11111#M155</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Works great! Thanks a lot Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 03 Jul 2011 11:59:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/proc-sgplot-stacked-vbar-colors/m-p/11111#M155</guid>
      <dc:creator>CColpaert</dc:creator>
      <dc:date>2011-07-03T11:59:23Z</dc:date>
    </item>
  </channel>
</rss>

