<?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 how can I have the sgplot vbars change color based on target (refline) in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/how-can-I-have-the-sgplot-vbars-change-color-based-on-target/m-p/416873#M14316</link>
    <description>&lt;P&gt;Here's my code in SAS 9.04 TS1M3. I'd like to have the vbar colors change based on whether they are on or over the target line (green), coming up to the target line (lime-yellow-orange), no where near the target line (red). Currently the vbar colors are based on how close they are to the top of the graph instead of the target line. Any help is appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data date_visits;&lt;BR /&gt;input date $CHAR10. visits 8.;&lt;BR /&gt;datalines;&lt;/P&gt;
&lt;P&gt;11/01/2016 136&lt;BR /&gt;12/01/2016 150&lt;BR /&gt;01/01/2017 161&lt;BR /&gt;02/01/2017 150&lt;BR /&gt;03/01/2017 160&lt;BR /&gt;04/01/2017 152&lt;BR /&gt;05/01/2017 144&lt;BR /&gt;06/01/2017 158&lt;BR /&gt;07/01/2017 165&lt;BR /&gt;08/01/2017 173&lt;BR /&gt;09/01/2017 170&lt;BR /&gt;10/01/2017 195&lt;BR /&gt;11/01/2017 201&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sgplot data=date_visits NOAUTOLEGEND;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; vbar date / response=visits&lt;BR /&gt;&amp;nbsp;&amp;nbsp; nostatlabel colorresponse=visits&lt;BR /&gt;&amp;nbsp;&amp;nbsp; colormodel=(red yellow green);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; refline 150 / axis=y lineattrs=(pattern=2 thickness=2px) label='Target 150'; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; xaxis discreteorder=data label="Month";&lt;BR /&gt;&amp;nbsp;&amp;nbsp; yaxis label="visits" minor max=250;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;run;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.GIF" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16896iAA227B052C50CAA2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.GIF" alt="Capture.GIF" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Nov 2017 20:47:38 GMT</pubDate>
    <dc:creator>robby_beum</dc:creator>
    <dc:date>2017-11-28T20:47:38Z</dc:date>
    <item>
      <title>how can I have the sgplot vbars change color based on target (refline)</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/how-can-I-have-the-sgplot-vbars-change-color-based-on-target/m-p/416873#M14316</link>
      <description>&lt;P&gt;Here's my code in SAS 9.04 TS1M3. I'd like to have the vbar colors change based on whether they are on or over the target line (green), coming up to the target line (lime-yellow-orange), no where near the target line (red). Currently the vbar colors are based on how close they are to the top of the graph instead of the target line. Any help is appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data date_visits;&lt;BR /&gt;input date $CHAR10. visits 8.;&lt;BR /&gt;datalines;&lt;/P&gt;
&lt;P&gt;11/01/2016 136&lt;BR /&gt;12/01/2016 150&lt;BR /&gt;01/01/2017 161&lt;BR /&gt;02/01/2017 150&lt;BR /&gt;03/01/2017 160&lt;BR /&gt;04/01/2017 152&lt;BR /&gt;05/01/2017 144&lt;BR /&gt;06/01/2017 158&lt;BR /&gt;07/01/2017 165&lt;BR /&gt;08/01/2017 173&lt;BR /&gt;09/01/2017 170&lt;BR /&gt;10/01/2017 195&lt;BR /&gt;11/01/2017 201&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sgplot data=date_visits NOAUTOLEGEND;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; vbar date / response=visits&lt;BR /&gt;&amp;nbsp;&amp;nbsp; nostatlabel colorresponse=visits&lt;BR /&gt;&amp;nbsp;&amp;nbsp; colormodel=(red yellow green);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; refline 150 / axis=y lineattrs=(pattern=2 thickness=2px) label='Target 150'; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; xaxis discreteorder=data label="Month";&lt;BR /&gt;&amp;nbsp;&amp;nbsp; yaxis label="visits" minor max=250;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;run;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.GIF" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16896iAA227B052C50CAA2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.GIF" alt="Capture.GIF" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 20:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/how-can-I-have-the-sgplot-vbars-change-color-based-on-target/m-p/416873#M14316</guid>
      <dc:creator>robby_beum</dc:creator>
      <dc:date>2017-11-28T20:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: how can I have the sgplot vbars change color based on target (refline)</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/how-can-I-have-the-sgplot-vbars-change-color-based-on-target/m-p/416878#M14317</link>
      <description>&lt;P&gt;You will want to use a range attribute map.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://go.documentation.sas.com/?docsetId=grstatproc&amp;amp;docsetTarget=p1cnbdobxlbk0jn1an1r978ohy7j.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://go.documentation.sas.com/?docsetId=grstatproc&amp;amp;docsetTarget=p1cnbdobxlbk0jn1an1r978ohy7j.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Examples:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/graphicallyspeaking/2017/06/26/advanced-ods-graphics-range-attribute-maps/" target="_blank"&gt;https://blogs.sas.com/content/graphicallyspeaking/2017/06/26/advanced-ods-graphics-range-attribute-maps/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/graphicallyspeaking/2013/04/14/attributes-map-3-range-attribute-map/&amp;nbsp;" target="_blank"&gt;https://blogs.sas.com/content/graphicallyspeaking/2013/04/14/attributes-map-3-range-attribute-map/&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will play with it and I might give a more detailed response later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 20:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/how-can-I-have-the-sgplot-vbars-change-color-based-on-target/m-p/416878#M14317</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-11-28T20:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: how can I have the sgplot vbars change color based on target (refline)</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/how-can-I-have-the-sgplot-vbars-change-color-based-on-target/m-p/416883#M14319</link>
      <description>&lt;P&gt;Something like this.&amp;nbsp; You will no doubt want to tweak my colors and value ranges associated with the colors to be more to your liking.&amp;nbsp; There is some subjectivity in this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data date_visits;
input date $CHAR10. visits 8.;
datalines;
11/01/2016 136
12/01/2016 150
01/01/2017 161
02/01/2017 150
03/01/2017 160
04/01/2017 152
05/01/2017 144
06/01/2017 158
07/01/2017 165
08/01/2017 173
09/01/2017 170
10/01/2017 195
11/01/2017 201
;

data rangeattrmap;
   id = "myID";
   length colormodel1 colormodel2 $ 8 min 8;
   input max colormodel2;
   min = ifn(_n_ = 1, 0, lag(max));
   colormodel1 = ifc(_n_ = 1, 'red', lag(colormodel2));
   datalines;
130 red
140 orange
150 yellow
201 green
;

proc print; run;

proc sgplot data=date_visits NOAUTOLEGEND rattrmap=rangeattrmap;
   vbar date / response=visits nostatlabel colorresponse=visits rattrid=myID;
   refline 150 / axis=y lineattrs=(pattern=2 thickness=2px) label='Target 150';
   xaxis discreteorder=data label="Month";
   yaxis label="visits" minor max=250;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Nov 2017 21:04:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/how-can-I-have-the-sgplot-vbars-change-color-based-on-target/m-p/416883#M14319</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-11-28T21:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: how can I have the sgplot vbars change color based on target (refline)</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/how-can-I-have-the-sgplot-vbars-change-color-based-on-target/m-p/416894#M14323</link>
      <description>&lt;P&gt;I would also suggest creating a new variable Delta=Visits-150.&amp;nbsp; Then, you can set ColorResponse=Delta instead of Visits.&amp;nbsp; To get consistent colors based on delta amount (or %), use a RangeAttrMap as suggested by Warren.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 21:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/how-can-I-have-the-sgplot-vbars-change-color-based-on-target/m-p/416894#M14323</guid>
      <dc:creator>Jay54</dc:creator>
      <dc:date>2017-11-28T21:21:51Z</dc:date>
    </item>
  </channel>
</rss>

