<?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: Recreate a graph with two mirrored histograms in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Recreate-a-graph-with-two-mirrored-histograms/m-p/906669#M24227</link>
    <description>&lt;P&gt;Check Rick.Wicklin 's blog:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2023/05/01/overlay-curve-histogram-sas.html" target="_blank" rel="noopener"&gt;Overlay a curve on a histogram in SAS - The DO Loop&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
That would be better if you post some real data.
*/
data have;
call streaminit(123);
do group='ON-PUMP','OFF-PUMP';
 do id=1 to 200;
  matched=rand('bern',0.6);
  ps=rand('uniform');
  group2=group;
  output;
 end;
end;
run;


ods select none;
proc sgplot data=have;
histogram ps/group=group scale=count nbins=20;
ods output sgplot=sgplot1;
run;

proc sgplot data=have(where=(matched=1));
histogram ps/group=group2 scale=count nbins=20;
ods output sgplot=sgplot2;
run;
ods select all;

data sgplot1;
 set sgplot1;
 if BIN_PS_GROUP_GROUP_SCALE_cou__GP='ON-PUMP' then 
 BIN_PS_GROUP_GROUP_SCALE_cou___Y=-BIN_PS_GROUP_GROUP_SCALE_cou___Y;
 keep BIN_PS_GROUP_GROUP_SCALE_cou__GP BIN_PS_GROUP_GROUP_SCALE_cou___Y BIN_PS_GROUP_GROUP_SCALE_cou___X;
run;
data sgplot2;
 set sgplot2;
 if BIN_PS_GROUP_GROUP2_SCALE_co__GP='ON-PUMP' then 
 BIN_PS_GROUP_GROUP2_SCALE_co___Y=-BIN_PS_GROUP_GROUP2_SCALE_co___Y;
 keep BIN_PS_GROUP_GROUP2_SCALE_co__GP BIN_PS_GROUP_GROUP2_SCALE_co___Y BIN_PS_GROUP_GROUP2_SCALE_co___X;
run;
data want;
 merge sgplot1 sgplot2;
run;


proc format;
picture fmt
low-0='00009';
run;
proc sgplot data=want noautolegend;
format BIN_PS_GROUP_GROUP_SCALE_cou___Y fmt.;
styleattrs datacolors=( darkgreen lightgreen) AXISEXTENT=data;
/*styleattrs datacolors=( CX006837 CXC2E699) AXISEXTENT=data;*/
 vbarparm category=BIN_PS_GROUP_GROUP_SCALE_cou___X 
          response=BIN_PS_GROUP_GROUP_SCALE_cou___Y /
          barwidth=1 group=BIN_PS_GROUP_GROUP_SCALE_cou__GP outlineattrs=(color=grey) nofill;
 inset 'OFF-PUMP'/textattrs=(color=lightgreen) position=top;

 vbarparm category=BIN_PS_GROUP_GROUP2_SCALE_co___X 
          response=BIN_PS_GROUP_GROUP2_SCALE_co___Y /
          barwidth=1 group=BIN_PS_GROUP_GROUP_SCALE_cou__GP outlineattrs=(color=grey);
 inset 'ON-PUMP'/textattrs=(color=darkgreen) position=bottom;

xaxis values=(0 to 1 by 0.2) type=linear display=(nolabel) offsetmin=0.05 offsetmax=0.05;
yaxis label='n of subject' offsetmin=0.1 offsetmax=0.1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1701942072202.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90940iD126801C0B74D282/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1701942072202.png" alt="Ksharp_0-1701942072202.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Dec 2023 09:41:18 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2023-12-07T09:41:18Z</dc:date>
    <item>
      <title>Recreate a graph with two mirrored histograms</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Recreate-a-graph-with-two-mirrored-histograms/m-p/906445#M24225</link>
      <description>&lt;P&gt;I have seen the following graph in this paper:&amp;nbsp;&lt;A href="https://doi.org/10.1093/ejcts/ezy167" target="_blank" rel="noopener"&gt;https://doi.org/10.1093/ejcts/ezy167&lt;/A&gt;&lt;BR /&gt;It shows the distribution of propensity scores for two groups, highlighting the patients that have been matched using the score.&lt;/P&gt;&lt;P&gt;Imagine that I have a data set DATA with three variables:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;MATCHED: 0/1 variable to identify the matched patients&lt;/LI&gt;&lt;LI&gt;PS: propensity scores for all the patients&lt;/LI&gt;&lt;LI&gt;GROUP: variable that defines if the patients are in the ON-PUMP or OFF-PUMP group.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;How could I replicate this graph using PROC SGPLOT ?&amp;nbsp;&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="ABohyn_0-1701870943300.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90857iC2E4321512214C43/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ABohyn_0-1701870943300.png" alt="ABohyn_0-1701870943300.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 14:02:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Recreate-a-graph-with-two-mirrored-histograms/m-p/906445#M24225</guid>
      <dc:creator>ABohyn</dc:creator>
      <dc:date>2023-12-06T14:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Recreate a graph with two mirrored histograms</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Recreate-a-graph-with-two-mirrored-histograms/m-p/906449#M24226</link>
      <description>&lt;P&gt;Google finds an answer quickly&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/graphicallyspeaking/2013/11/21/comparative-histograms/" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/graphicallyspeaking/2013/11/21/comparative-histograms/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and other solutions are found via Google as well&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 14:23:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Recreate-a-graph-with-two-mirrored-histograms/m-p/906449#M24226</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-12-06T14:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: Recreate a graph with two mirrored histograms</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Recreate-a-graph-with-two-mirrored-histograms/m-p/906669#M24227</link>
      <description>&lt;P&gt;Check Rick.Wicklin 's blog:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2023/05/01/overlay-curve-histogram-sas.html" target="_blank" rel="noopener"&gt;Overlay a curve on a histogram in SAS - The DO Loop&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
That would be better if you post some real data.
*/
data have;
call streaminit(123);
do group='ON-PUMP','OFF-PUMP';
 do id=1 to 200;
  matched=rand('bern',0.6);
  ps=rand('uniform');
  group2=group;
  output;
 end;
end;
run;


ods select none;
proc sgplot data=have;
histogram ps/group=group scale=count nbins=20;
ods output sgplot=sgplot1;
run;

proc sgplot data=have(where=(matched=1));
histogram ps/group=group2 scale=count nbins=20;
ods output sgplot=sgplot2;
run;
ods select all;

data sgplot1;
 set sgplot1;
 if BIN_PS_GROUP_GROUP_SCALE_cou__GP='ON-PUMP' then 
 BIN_PS_GROUP_GROUP_SCALE_cou___Y=-BIN_PS_GROUP_GROUP_SCALE_cou___Y;
 keep BIN_PS_GROUP_GROUP_SCALE_cou__GP BIN_PS_GROUP_GROUP_SCALE_cou___Y BIN_PS_GROUP_GROUP_SCALE_cou___X;
run;
data sgplot2;
 set sgplot2;
 if BIN_PS_GROUP_GROUP2_SCALE_co__GP='ON-PUMP' then 
 BIN_PS_GROUP_GROUP2_SCALE_co___Y=-BIN_PS_GROUP_GROUP2_SCALE_co___Y;
 keep BIN_PS_GROUP_GROUP2_SCALE_co__GP BIN_PS_GROUP_GROUP2_SCALE_co___Y BIN_PS_GROUP_GROUP2_SCALE_co___X;
run;
data want;
 merge sgplot1 sgplot2;
run;


proc format;
picture fmt
low-0='00009';
run;
proc sgplot data=want noautolegend;
format BIN_PS_GROUP_GROUP_SCALE_cou___Y fmt.;
styleattrs datacolors=( darkgreen lightgreen) AXISEXTENT=data;
/*styleattrs datacolors=( CX006837 CXC2E699) AXISEXTENT=data;*/
 vbarparm category=BIN_PS_GROUP_GROUP_SCALE_cou___X 
          response=BIN_PS_GROUP_GROUP_SCALE_cou___Y /
          barwidth=1 group=BIN_PS_GROUP_GROUP_SCALE_cou__GP outlineattrs=(color=grey) nofill;
 inset 'OFF-PUMP'/textattrs=(color=lightgreen) position=top;

 vbarparm category=BIN_PS_GROUP_GROUP2_SCALE_co___X 
          response=BIN_PS_GROUP_GROUP2_SCALE_co___Y /
          barwidth=1 group=BIN_PS_GROUP_GROUP_SCALE_cou__GP outlineattrs=(color=grey);
 inset 'ON-PUMP'/textattrs=(color=darkgreen) position=bottom;

xaxis values=(0 to 1 by 0.2) type=linear display=(nolabel) offsetmin=0.05 offsetmax=0.05;
yaxis label='n of subject' offsetmin=0.1 offsetmax=0.1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1701942072202.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90940iD126801C0B74D282/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1701942072202.png" alt="Ksharp_0-1701942072202.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 09:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Recreate-a-graph-with-two-mirrored-histograms/m-p/906669#M24227</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-12-07T09:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: Recreate a graph with two mirrored histograms</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Recreate-a-graph-with-two-mirrored-histograms/m-p/906706#M24228</link>
      <description>&lt;P&gt;This type of graph is sometimes called a &lt;EM&gt;butterfly plot&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;Your example is slightly more complicated than the one in the blog post, &lt;A href="https://blogs.sas.com/content/iml/2018/05/23/butterfly-plot.html" target="_self"&gt;"A butterfly plot for comparing distributions,"&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;but I think that article is a good place to start.&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 14:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Recreate-a-graph-with-two-mirrored-histograms/m-p/906706#M24228</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-12-07T14:24:46Z</dc:date>
    </item>
  </channel>
</rss>

