<?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: sgplot: shading background of a plot in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825659#M23002</link>
    <description>so, it's not possible to define ranges for categorial axis, is that right?</description>
    <pubDate>Wed, 27 Jul 2022 13:10:46 GMT</pubDate>
    <dc:creator>Anita_n</dc:creator>
    <dc:date>2022-07-27T13:10:46Z</dc:date>
    <item>
      <title>sgplot: shading background of a plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825632#M23000</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have this code and I wish to shade the backgroud of plot indicating the normal and critical&amp;nbsp; areas.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines;
input type $10. num_pat num_centers 3.;

datalines;
liver       8  6
stomach     4  6
breast     20  10
ovary      15  8
kidney     18  10
leucemia   16  2
intestine  4   2
CNS        5   1
lung      14   7
uterus    16   8
;

run;

data have;
set have;
r_value=num_pat/num_centers;

if r_value &amp;lt; 2 then grup="critical";else grup="normal";
if grup="normal" then high=.; else if grup="critical" then high=1.99;

label r_value= R-Values;
run;

proc sort data=have;
by descending r_value;
run;


proc sgplot data=have noautolegend ;
styleattrs datacolors=('CX5F9EA0' 'CX00FFFF' ) datacontrastcolors=('CX5F9EA0' 'CX00FFFF' );
label;

vbar type /response= num_centers  missing baselineattrs=(thickness=0) legendlabel='Number of treatment centers' name='a';

vbar type /response= num_pat missing baselineattrs=(thickness=0) barwidth=0.5 legendlabel='Number of patients' name='b'; 

xaxis type=discrete discreteorder=data display=(nolabel) valueattrs=(size=6pt family=arial);

yaxis  display=(nolabel) valueattrs=(size=7pt family=arial) grid;
y2axis  labelattrs=(size=8pt family=arial color=dimgray) valueattrs=(size=7pt family=arial);

vline type / response=r_value y2axis lineattrs=(color=gold  pattern=solid thickness=2) nostatlabel  legendlabel='R-values' name='c';

keylegend 'a' 'b' 'c' / location=outside position=bottom across=0 title="" valueattrs=(size=7pt family=arial) outerpad=(top=0.2cm) noborder;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;something like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Anita_n_0-1658919971564.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73789i230CFDF965A4400F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Anita_n_0-1658919971564.png" alt="Anita_n_0-1658919971564.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;how do I do that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 11:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825632#M23000</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-07-27T11:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot: shading background of a plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825645#M23001</link>
      <description>&lt;P&gt;Define "critical area" for your plot, which is two overlayed VBAR plots and has nothing in common with the "example" picture.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An axis for a continuous variable can be defined with ranges in data and overlay any of a number of things. But your xaxis for VBAR is categorical and so you are going to have some fun defining a range of the xaxis values.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 12:43:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825645#M23001</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-27T12:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot: shading background of a plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825659#M23002</link>
      <description>so, it's not possible to define ranges for categorial axis, is that right?</description>
      <pubDate>Wed, 27 Jul 2022 13:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825659#M23002</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-07-27T13:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot: shading background of a plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825669#M23003</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168930"&gt;@Anita_n&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could add the WALLCOLOR= option to your STYLEATTRS statement to define the color of the "normal" area and add one or two VBAR statements to draw the "critical" area (using a constant variable).&lt;/P&gt;
&lt;PRE&gt;data want;
set have;
&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;critlimit=2;
label critlimit='R-Values';&lt;/STRONG&gt;&lt;/FONT&gt;
run;

proc sgplot data=&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;want&lt;/STRONG&gt;&lt;/FONT&gt; noautolegend ;
styleattrs datacolors=('CX5F9EA0' 'CX00FFFF') datacontrastcolors=('CX5F9EA0' 'CX00FFFF') &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;wallcolor=lightgrey&lt;/FONT&gt;&lt;/STRONG&gt;;
label;
&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;vbar type /response= critlimit nooutline barwidth=1 fillattrs=(color=lightpink) y2axis discreteoffset=-0.1;
vbar type /response= critlimit nooutline barwidth=1 fillattrs=(color=lightpink) y2axis discreteoffset= 0.1;
&lt;/FONT&gt;&lt;/STRONG&gt;
vbar type /response= num_centers &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;fillattrs=(color='CX5F9EA0')&lt;/FONT&gt;&lt;/STRONG&gt; missing baselineattrs=(thickness=0) legendlabel='Number of treatment centers' name='a';

vbar type /response= num_pat &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;fillattrs=(color='CX00FFFF')&lt;/STRONG&gt;&lt;/FONT&gt; missing baselineattrs=(thickness=0) barwidth=0.5 legendlabel='Number of patients' name='b'; 

xaxis type=discrete discreteorder=data display=(nolabel) valueattrs=(size=6pt family=arial);

yaxis  display=(nolabel) valueattrs=(size=7pt family=arial) grid &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;offsetmin=0&lt;/FONT&gt;&lt;/STRONG&gt;;
y2axis  labelattrs=(size=8pt family=arial color=dimgray) valueattrs=(size=7pt family=arial) &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;min=0.66667&lt;/FONT&gt;&lt;/STRONG&gt;;

vline type / response=r_value y2axis lineattrs=(color=gold  pattern=solid thickness=2) nostatlabel  legendlabel='R-values' name='c';

keylegend 'a' 'b' 'c' / location=outside position=bottom across=0 title="" valueattrs=(size=7pt family=arial) outerpad=(top=0.2cm) noborder;
run;&lt;/PRE&gt;
&lt;P&gt;(I had to add the FILLATTRS= and MIN= options to existing statements because of interactions with the new VBAR statements. The OFFSETMIN=0 option avoids a margin of background color below the bars.)&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 13:37:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825669#M23003</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-07-27T13:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot: shading background of a plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825676#M23004</link>
      <description>&lt;P&gt;In this case, you might want to use a SERIES plot instead of a VLINE, unless you need the data summarized. For the background, you just need BLOCK plot. Here is a simple example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data air;
set sashelp.air;
if (date &amp;lt;= '01jan1958'd) then period="earlier";
else period="later";
run;

proc sgplot data=air;
block x=date block=period / filltype=alternate;
series x=date y=air;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-07-27 at 9.44.49 AM.png" style="width: 603px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73798iD9B3D810062BF6C5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2022-07-27 at 9.44.49 AM.png" alt="Screen Shot 2022-07-27 at 9.44.49 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 13:47:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825676#M23004</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2022-07-27T13:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot: shading background of a plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825679#M23005</link>
      <description>&lt;P&gt;Sorry, I just realized that your code also has VBARs in it. What I would do is use PROC SUMMARY or PROC MEANS to summarize the data. Then, use VBARPARMs and a SERIES instead so that I can put a BLOCK plot behind it, like in the example in my previous post.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 13:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825679#M23005</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2022-07-27T13:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot: shading background of a plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825682#M23006</link>
      <description>&lt;P&gt;Thanks to you all for your suggestions&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;: I adjusted your code this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if high ^=. then critlimit=35;
run;

proc sgplot data=want noautolegend ;
styleattrs datacolors=('CX5F9EA0' 'CX00FFFF') datacontrastcolors=('CX5F9EA0' 'CX00FFFF') wallcolor=dimgrey;
label;
vbar type /response= critlimit nooutline barwidth=1 fillattrs=(color=lightpink) y2axis discreteoffset=-0.1;
vbar type /response= critlimit nooutline barwidth=1 fillattrs=(color=lightpink) y2axis discreteoffset= 0.1;

vbar type /response= num_centers fillattrs=(color='CX5F9EA0') missing baselineattrs=(thickness=0) legendlabel='Number of treatment centers' name='a';
vbar type /response= num_pat fillattrs=(color='CX00FFFF') missing baselineattrs=(thickness=0) barwidth=0.5 legendlabel='Number of patients' name='b'; 

xaxis type=discrete discreteorder=data display=(nolabel) valueattrs=(size=6pt family=arial);

yaxis  display=(nolabel) valueattrs=(size=7pt family=arial) grid offsetmin=0;
y2axis  labelattrs=(size=8pt family=arial color=dimgray) valueattrs=(size=7pt family=arial) min=0.66667;

vline type / response=r_value y2axis lineattrs=(color=gold  pattern=solid thickness=2) nostatlabel  legendlabel='R-values' name='c';

inset "critical areas" / position=NE textattrs=(color=red family=arial size=7pt weight=bold);
inset "normal areas" / position=NW textattrs=(color=black family=arial size=7pt weight=bold);

keylegend 'a' 'b' 'c' / location=outside position=bottom across=0 title="" valueattrs=(size=7pt family=arial) outerpad=(top=0.2cm) noborder;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I don't know if it make sense to do it this way but it seems to produce what I want&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 14:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825682#M23006</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-07-27T14:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot: shading background of a plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825686#M23007</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168930"&gt;@Anita_n&lt;/a&gt;&amp;nbsp;wrote:
&lt;P&gt;I don't know if it make sense to do it this way but it seems to produce what I want&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Great that it produces what you want. (But did you notice the change of the y2-axis label?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My interpretation of&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;if r_value &amp;lt; 2 then grup="critical";else grup="normal";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;was that the "critical" area was a &lt;EM&gt;horizontal&lt;/EM&gt; stripe (unlike in the picture you posted) with upper limit &lt;FONT face="courier new,courier"&gt;r_value=2&lt;/FONT&gt;. If I had realized that it was really meant to be &lt;EM&gt;vertical&lt;/EM&gt;, I would have suggested a BLOCK statement (as DanH_sas did) because I produced those block plots in the past.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 14:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825686#M23007</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-07-27T14:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot: shading background of a plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825689#M23009</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;yes , you right. that is the right defination for the critical and normal areas but I want the background to start from 0 to the maximum y2axis value (that is why I am asking if there is a better way to do that). I will can also try&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15130"&gt;@DanH_sas&lt;/a&gt;&amp;nbsp; suggestion but at the moment your code worked for me, thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 14:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825689#M23009</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-07-27T14:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot: shading background of a plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825703#M23010</link>
      <description>&lt;P&gt;For an example of this kind of block plot, see&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2016/11/21/forecast-regions.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2016/11/21/forecast-regions.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 15:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825703#M23010</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-07-27T15:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot: shading background of a plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825709#M23012</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;the Vbarparm statement in combination with series and block statement is a very efficient way of solving this problem. I like that&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;. Thankyou all for the help&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 15:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/m-p/825709#M23012</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-07-27T15:51:40Z</dc:date>
    </item>
  </channel>
</rss>

