<?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 SCATTER with Quantile Bins? in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611708#M19239</link>
    <description>&lt;P&gt;Sure. use the QNTL function unconditionally for the Y axis (horizontal bins), then subset (use LOC function) and use the QNTL function again on each strip to subdivide in the direction of the X axis.&amp;nbsp; I performed similar computations in my article about the 2-D bin plot, but I was interested in using evenly spaced cutpoints in each direction (thus a regular grid) whereas the OP is interested in quantile-based cutpoints.&amp;nbsp; I suggest using rectangles and the polygon plot for overlaying the grid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's a great question! I'd write the program but I'm trying to finish a task. I'll look at it later unless someone else programs it first.&lt;/P&gt;</description>
    <pubDate>Fri, 13 Dec 2019 19:30:54 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2019-12-13T19:30:54Z</dc:date>
    <item>
      <title>SGPLOT SCATTER with Quantile Bins?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611669#M19235</link>
      <description>&lt;P&gt;The following scatter plot divides the observations into 10 groups using y-axis first and then 10 subgroups for each using x-axis second.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34757i62B1D3CEEF657475/image-size/medium?v=v2&amp;amp;px=400" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Can I do this dependent grouping in SAS? This is my simple trial of independent grouping in SAS, but I cannot limit the length of each LINEPARM in SGPLOT, so wonder whether dependent grouping is available.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34759i6F82F6EFA10BB956/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SGPlot.png" alt="SGPlot.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here is the code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _01;
do i=1 to 100;
x=rannor(1);
y=x+rannor(1);
output;
end;
run;
proc iml;
use _01;
read all var{x y};
call qntl(xq,x);
call qntl(yq,y);
call symputx("xq",rowcat(char(xq)`+" "));
call symputx("yq",rowcat(char(yq)`+" "));
quit;
proc sgplot noautolegend;
scatter x=x y=y;
lineparm x=%scan(&amp;amp;xq.,1," ") y=0 slope=.;
lineparm x=%scan(&amp;amp;xq.,2," ") y=0 slope=.;
lineparm x=%scan(&amp;amp;xq.,3," ") y=0 slope=.;
lineparm x=0 y=%scan(&amp;amp;yq.,1," ") slope=0;
lineparm x=0 y=%scan(&amp;amp;yq.,2," ") slope=0;
lineparm x=0 y=%scan(&amp;amp;yq.,3," ") slope=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 17:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611669#M19235</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2019-12-13T17:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT SCATTER with Quantile Bins?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611684#M19236</link>
      <description>&lt;P&gt;What version of SAS are you using?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 18:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611684#M19236</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2019-12-13T18:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT SCATTER with Quantile Bins?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611685#M19237</link>
      <description>&lt;P&gt;It is SAS 9.4 TS1M5.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 18:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611685#M19237</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2019-12-13T18:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT SCATTER with Quantile Bins?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611701#M19238</link>
      <description>&lt;P&gt;The &lt;STRONG&gt;DRAWING&lt;/STRONG&gt; of it is definitely possible, using things such as annotation, VECTOR plot, of possibly POLYGON plot. The tricky part to making it look like the original figure is to figure out the min/max points within each bin.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;, any way to get this information from PROC IML?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 19:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611701#M19238</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2019-12-13T19:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT SCATTER with Quantile Bins?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611708#M19239</link>
      <description>&lt;P&gt;Sure. use the QNTL function unconditionally for the Y axis (horizontal bins), then subset (use LOC function) and use the QNTL function again on each strip to subdivide in the direction of the X axis.&amp;nbsp; I performed similar computations in my article about the 2-D bin plot, but I was interested in using evenly spaced cutpoints in each direction (thus a regular grid) whereas the OP is interested in quantile-based cutpoints.&amp;nbsp; I suggest using rectangles and the polygon plot for overlaying the grid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's a great question! I'd write the program but I'm trying to finish a task. I'll look at it later unless someone else programs it first.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 19:30:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611708#M19239</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-12-13T19:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT SCATTER with Quantile Bins?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611797#M19240</link>
      <description>&lt;P&gt;OK . How about this one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data heart;
set sashelp.heart(obs=2000 keep=height weight
where=(height is not missing and weight is not missing)) ;
run;

proc rank data=heart out=have groups=10 ties=high;
var height;
ranks r_height;
run;
proc sort data=have;by r_height;run;
proc rank data=have out=have1 groups=10 ties=high;
by r_height;
var weight;
ranks r_weight;
run;
proc sql;
create table have2 as
select a.*,r_weight,min_w,max_w from (
select r_height,min(height) as min_h,max(height) as max_h,
min(weight) as min_w2,max(weight) as max_w2
 from have1
  group by r_height) as a
left join (
select r_height,r_weight,min(weight) as min_w,max(weight) as max_w
 from have1
  group by r_height,r_weight) as b
on a.r_height=b.r_height;
quit;

data have3;
 set have2;
 by r_height;
 if first.r_height then do;
 o_y=max_h;o_x=min_w;
 y=min_h;x=min_w;
 
 o_y2=max_h;o_x2=min_w2;
 y2=max_h;x2=max_w2;
 output;
 end;
 
 o_y=max_h;o_x=max_w;
 y=min_h;x=max_w;
 
 o_y2=min_h;o_x2=min_w2;
 y2=min_h;x2=max_w2;
 
 output;
run;

data want;
 set heart have3;
run;
proc sgplot data=want noautolegend;
scatter x=weight y=height/ transparency=0.5;
vector x=x y=y / xorigin=o_x yorigin=o_y noarrowheads lineattrs=(color=green);
vector x=x2 y=y2 / xorigin=o_x2 yorigin=o_y2 noarrowheads lineattrs=(color=red);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="x.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34773i3B90E302C0CE75A1/image-size/large?v=v2&amp;amp;px=999" role="button" title="x.png" alt="x.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 13:56:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611797#M19240</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-14T13:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT SCATTER with Quantile Bins?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611822#M19241</link>
      <description>&lt;P&gt;Here I also attach my version.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
do i=1 to 100;
x=rannor(1);
y=x+rannor(1);
output;
end;
run;
proc iml;
use a;
read all var{x y};
call qntl(qx,x,do(0,1,1/3));
call qntl(q1,y[loc(x&amp;lt;=qx[2])],do(0,1,1/3));
call qntl(q2,y[loc(x&amp;gt;qx[2] &amp;amp; x&amp;lt;=qx[3])],do(0,1,1/3));
call qntl(q3,y[loc(x&amp;gt;qx[3])],do(0,1,1/3));
qy=q1||q2||q3;
b=j(45,2);
do i=1 to 3;
do j=1 to 3;
do k=1 to 5;
if k=1 then b[15*i+5*j+k-20,]=qx[i]||qy[j,i];
else if k=2 then b[15*i+5*j+k-20,]=qx[i]||qy[j+1,i];
else if k=3 then b[15*i+5*j+k-20,]=qx[i+1]||qy[j+1,i];
else if k=4 then b[15*i+5*j+k-20,]=qx[i+1]||qy[j,i];
else b[15*i+5*j+k-20,]=qx[i]||qy[j,i];
end;
end;
end;
create b(rename=(col1=x1 col2=y1)) from b;
append from b;
quit;
data b;
set b;
if mod(_n_,5)=1 then function="polyline";
else function="polycont";
drawspace="datavalue";
linethickness=1;
run;
proc sgplot data=a sganno=b;
scatter x=x y=y;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And the output here.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34774i6C7DAF56B19D855A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SGPlot.png" alt="SGPlot.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 23:02:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611822#M19241</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2019-12-14T23:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT SCATTER with Quantile Bins?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611863#M19242</link>
      <description>&lt;P&gt;The original request was for partitioning by the Y quantiles first, then partitioning by X within each Y region. However, the picture looks like the subdivisions are first by X and then by Y.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2019 10:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611863#M19242</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-12-15T10:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT SCATTER with Quantile Bins?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611905#M19243</link>
      <description>&lt;P&gt;The Y and then X example.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
do i=1 to 100;
x=rannor(1);
y=x+rannor(1);
output;
end;
run;
proc iml;
use a;
read all var{x y};
call qntl(qy,y,do(0,1,1/3));
call qntl(q1,x[loc(y&amp;lt;=qy[2])],do(0,1,1/3));
call qntl(q2,x[loc(y&amp;gt;qy[2] &amp;amp; y&amp;lt;=qy[3])],do(0,1,1/3));
call qntl(q3,x[loc(y&amp;gt;qy[3])],do(0,1,1/3));
qx=q1||q2||q3;
b=j(45,2);
do i=1 to 3;
do j=1 to 3;
do k=1 to 5;
if k=1 then b[15*i+5*j+k-20,]=qx[j,i]||qy[i];
if k=2 then b[15*i+5*j+k-20,]=qx[j+1,i]||qy[i];
if k=3 then b[15*i+5*j+k-20,]=qx[j+1,i]||qy[i+1];
if k=4 then b[15*i+5*j+k-20,]=qx[j,i]||qy[i+1];
if k=5 then b[15*i+5*j+k-20,]=qx[j,i]||qy[i];
end;
end;
end;
create b(rename=(col1=x1 col2=y1)) from b;
append from b;
quit;
data b;
set b;
if mod(_n_,5)=1 then function="polyline";
else function="polycont";
drawspace="datavalue";
linethickness=1;
run;
ods listing gpath="!userprofile\desktop\";
ods graphics/reset;
ods results=off;
proc sgplot data=a sganno=b;
scatter x=x y=y;
run;
ods results=on;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And the results.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34789i278E339A98E0D69B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SGPlot.png" alt="SGPlot.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Actually, in SGANNO, I tried RECTANGLE first as POLYLINE requires 5 observations for each bin while RECTANGLE requires only 1, but I realized that the RECTANGLE output is slightly ugly as follows.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
do i=1 to 100;
x=rannor(1);
y=x+rannor(1);
output;
end;
run;
proc iml;
use a;
read all var{x y};
call qntl(qy,y,do(0,1,1/3));
call qntl(q1,x[loc(y&amp;lt;=qy[2])],do(0,1,1/3));
call qntl(q2,x[loc(y&amp;gt;qy[2] &amp;amp; y&amp;lt;=qy[3])],do(0,1,1/3));
call qntl(q3,x[loc(y&amp;gt;qy[3])],do(0,1,1/3));
qx=q1||q2||q3;
b=j(9,4);
do i=1 to 3;
do j=1 to 3;
b[3*i+j-3,]=qx[j,i]||qy[i]||qx[j+1,i]-qx[j,i]||qy[i+1]-qy[i];
end;
end;
create b(rename=(col1=x1 col2=y1 col3=width col4=height)) from b;
append from b;
quit;
data b;
set b;
function="rectangle";
drawspace="datavalue";
anchor="bottomleft";
linethickness=1;
widthunit="data";
heightunit="data";
run;
ods listing gpath="!userprofile\desktop\";
ods graphics/reset;
ods results=off;
proc sgplot data=a sganno=b;
scatter x=x y=y;
run;
ods results=on;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It seems RECTANGLE draws the lines one pixel outside the region, while POLYLINE draw the exact lines.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34790i889F8EA756DFEB45/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SGPlot.png" alt="SGPlot.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;POLYLINE seems to be better than RECTANGLE.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2019 18:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-SCATTER-with-Quantile-Bins/m-p/611905#M19243</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2019-12-15T18:46:10Z</dc:date>
    </item>
  </channel>
</rss>

