<?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: How to fill the peaks and valleys of a series plot? in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731223#M21280</link>
    <description>&lt;P&gt;See also a related idea:&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2015/07/20/density-shaded-tails.html" target="_self"&gt;Create a density curve with shaded tails&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 04 Apr 2021 11:35:11 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2021-04-04T11:35:11Z</dc:date>
    <item>
      <title>How to fill the peaks and valleys of a series plot?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731134#M21270</link>
      <description>&lt;P&gt;There was an interesting question on LinkedIn, where the desire was to fill the peaks of a series plot with one color, and the valleys as another color.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.linkedin.com/feed/update/urn:li:activity:6783694808239128576" target="_blank"&gt;https://www.linkedin.com/feed/update/urn:li:activity:6783694808239128576&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Fill.png" style="width: 699px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56873i053E339FC55AA0A7/image-size/large?v=v2&amp;amp;px=999" role="button" title="Fill.png" alt="Fill.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm wondering how folks would approach this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Graphing guru Kriss Harriss had the good idea of using bandplot, and posted the approach in his excellent Daily Coding series:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.linkedin.com/posts/krissharris_dailycoding-day91-sgf-activity-6783513455380041728-vO9n" target="_blank"&gt;https://www.linkedin.com/posts/krissharris_dailycoding-day91-sgf-activity-6783513455380041728-vO9n&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I played with this, I started with a sine wave and the goal of coloring the peaks and valleys different colors, without specifying the x-values to define each peak.&amp;nbsp; I got close to what I wanted, but unfortunately there is no /BREAK option for the band statement, so SGPLOT connects the peaks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data foo;
  do x = 0 to 3.14*4 by 0.01;
    y = sin(x);   
    output;
  end;
run;

data foo2 ; 
  set foo ;
  if y &amp;gt; .5 then do ;
    group=1 ;
    limit=.5 ;
  end ;
  else if y &amp;lt; -.75 then do ;
    group= 2 ;
    limit= -.75 ;
  end ;
run ;

proc sgplot data=foo2 ;
  series x=x y=y ;
  band x = x lower = limit upper = y   / group=group nomissinggroup;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My output, within the unwanted connecting bands highlighted:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Fill2.png" style="width: 796px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56874i1A3E2C39D810434E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Fill2.png" alt="Fill2.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought this was an interesting question, so was curious about other approaches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the OP has reference lines for each band, I think my approach might actually 'work' because you could make the reference lines cover the unwanted band lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 13:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731134#M21270</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2021-04-03T13:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill the peaks and valleys of a series plot?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731144#M21271</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like Simon Bacha opened an &lt;A href="https://communities.sas.com/t5/Graphics-Programming/How-do-I-add-specific-sections-in-figures/m-p/730732" target="_blank" rel="noopener"&gt;own thread&lt;/A&gt;&amp;nbsp;about this the day before yesterday and that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;'s solution avoids the problem of the connecting lines. I'm still trying to understand the trick, but it seems that the way he defines the limits is about as important as omitting the GROUP= option (and using two BAND statements instead).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data foo2 ; 
  set foo ;
  limit1 = min(y, .5) ;
  limit2 = max(y, -.75) ;
run ;

proc sgplot data=foo2 ;
  series x=x y=y ;
  band x = x lower = limit1 upper = y / fillattrs=(color=CX6F7EB3) legendlabel='Group 1' ;
  band x = x lower = limit2 upper = y / fillattrs=(color=CXD05B5B) legendlabel='Group 2' ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Apr 2021 15:06:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731144#M21271</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-04-03T15:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill the peaks and valleys of a series plot?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731147#M21272</link>
      <description>&lt;P&gt;Add options nooutline noextend to the band statement to get rid of the colored lines.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 15:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731147#M21272</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-04-03T15:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill the peaks and valleys of a series plot?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731153#M21273</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Add options nooutline noextend to the band statement to get rid of the colored lines.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;, for chiming in. These two options didn't seem to have an impact on the graph (with Quentin's data), which is why I omitted them for simplicity:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot34.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56876i73302FEF35F2E896/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGPlot34.png" alt="SGPlot34.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Of course, it doesn't hurt to include them and they could be important in other situations.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 15:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731153#M21273</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-04-03T15:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill the peaks and valleys of a series plot?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731158#M21274</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;mentioned, adding NOOUTLINE NOEXTEND doesn't avoid the connecting line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like your nifty solution avoids the connecting line by having data where the upper value and the lower value are the same, so I suspect SGPLOT is drawing a band with height 0.&amp;nbsp; So for my approach using group, the hack would be to add records for each group, something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data foo2 ; 
  set foo ;
  if y &amp;gt; .5 then do ;
    group=1 ;
    limit=.5 ;&lt;BR /&gt;    output ;
  end ;
  else if y &amp;lt; -.75 then do ;
    group= 2 ;
    limit= -.75 ;
    output ;&lt;BR /&gt;  end ;
  else do ;
    limit=y ;
    group=1 ; output ;
    group=2 ; output ;
  end ;
run ;


proc sgplot data=foo2 ;
  series x=x y=y ;
  band x = x lower = limit upper = y   / group=group nomissinggroup ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So in the absence of a /break option, looks like a band of height 0 achieves the same effect.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But your solution in the other thread is better than this one!&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 16:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731158#M21274</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2021-04-03T16:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill the peaks and valleys of a series plot?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731170#M21276</link>
      <description>&lt;P&gt;I guess you could do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data foo;
  do x = 0 to 3.14*4 by 0.01;
    y = sin(x) + 10;   
    output;
  end;
run;

data foo2 ; 
  set foo ;
  output;
  t = x; x = .;
  do Limit = 9.7, 9.2, 10.5, 10.75;
    if (y-10) / (limit-10) &amp;gt; 1 then z = y;
    else z = limit;
    output;
  end ;
run ;

proc sgplot data=foo2 ;
  band x = t lower = limit upper = z / group=limit nomissinggroup;
  series x = x y = y ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1617474533408.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56881i29BF16F6E750455D/image-size/large?v=v2&amp;amp;px=999" role="button" title="PGStats_0-1617474533408.png" alt="PGStats_0-1617474533408.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Note that the order is important in the list of limits, so that the more extreme values are named last.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 18:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731170#M21276</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-04-03T18:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill the peaks and valleys of a series plot?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731223#M21280</link>
      <description>&lt;P&gt;See also a related idea:&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2015/07/20/density-shaded-tails.html" target="_self"&gt;Create a density curve with shaded tails&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Apr 2021 11:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-fill-the-peaks-and-valleys-of-a-series-plot/m-p/731223#M21280</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-04-04T11:35:11Z</dc:date>
    </item>
  </channel>
</rss>

