<?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 make forest plot rectangles into squares in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/How-to-make-forest-plot-rectangles-into-squares/m-p/238497#M8648</link>
    <description>&lt;P&gt;What version of SAS are you using?&lt;/P&gt;</description>
    <pubDate>Wed, 09 Dec 2015 13:24:01 GMT</pubDate>
    <dc:creator>DanH_sas</dc:creator>
    <dc:date>2015-12-09T13:24:01Z</dc:date>
    <item>
      <title>How to make forest plot rectangles into squares</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-make-forest-plot-rectangles-into-squares/m-p/238491#M8645</link>
      <description>&lt;P&gt;I've been working on a forest plot and although it's in pretty good shape, there are some minor things I'm trying to fix:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current graph:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/1103iDACD21635A25405E/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="use this.gif" title="use this.gif" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What it should resemble (broadly - different data):&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/1104i9B91D9F3457E5F5F/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="sample.png" title="sample.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. Is there a way to change the rectangles on the SAS graph to squares, as in the graph above? &lt;/STRONG&gt;- ie, so when the weight is bigger, there's a bigger square rather than a wider rectangle?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively, is it possible to make the blue rectangles mostly transparent, so the line red line can be seen? Then I could add a dot using paint to indicate where the&amp;nbsp;HG value&amp;nbsp;is. &amp;nbsp;(Also, is it possible to make thie whole graph greyscale?)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Is it possible to stretch the diamond&amp;nbsp;so it starts at the lower CL and finishes at the UL? Looking at the code, I'm guessing there'd be no automated way to do this - would have to do it after the fact using paint. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help/pointers on where the code could be changed - have been playing around with it, but as a relatively new user, haven't &amp;nbsp;gotten too far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code used:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data forest;                                                                                                                            
   input Study $1-18 grp OddsRatio LowerCL UpperCL Weight;                                                                              
   format weight percent5. Q1 Q3 4.2 oddsratio lowercl uppercl 5.3;                                                                     
   ObsId=_N_;                                                                                                                           
   OR='HG'; LCL='LCL'; UCL='UCL'; WT='Weight';                                                                                          
   if grp=1 then do;                                                                                                                    
      weight=weight*.01;                                                                                                                
      Q1=OddsRatio-OddsRatio*weight;                                                                                                    
      Q3=OddsRatio+OddsRatio*weight;                                                                                                    
        lcl2=lowercl;                                                                                                                   
      ucl2=uppercl;                                                                                                                     
   end;                                                                                                                                 
   else study2=study;                                                                                                                   
datalines;                                                                                                                              
Study1				1	-0.170	-0.901	0.560	9.9
Study2				1	0.354	-0.530	1.237	6.8
Study3				1	-0.204	-1.186	0.779	5.5
Study4				1	-0.848	-1.842	0.146	5.4
Study5				1	0.495	-0.179	1.169	11.6
Study 6				1	-0.058	-0.568	0.453	20.3
Study 7				1	-0.345	-1.191	0.500	7.4
Study 8				1	-0.272	-1.335	0.792	4.7
Study 9				1	0.000	-0.494	0.494	21.7
Study 10			1	0.479	-0.410	1.368	6.7
Overall				2	-0.010	-0.240	0.220	.

;                                                                                                                                       
run;
                                                                                                                                        
proc sort data=forest out=forest2;                                                                                                      
   by descending obsid;                                                                                                                 
run;                                                                                                                                    
                                                                                                                                        
/* Add sequence numbers to each observation */                                                                                       
data forest3;                                                                                                                           
   set forest2 end=last;                                                                                                                
   retain fmtname 'Study' type 'n';                                                                                                     
   studyvalue=_n_;                                                                                                                      
   if study2='Overall' then study2value=1;                                                                                              
   else study2value = .;                                                                                                                
                                                                                                                                        
/* Output values and formatted strings to data set */                                                                                   
   label=study;                                                                                                                         
   start=studyvalue;                                                                                                                    
   end=studyvalue;                                                                                                                      
   output;                                                                                                                              
   if last then do;                                                                                                                     
      hlo='O';                                                                                                                          
      label='Other';                                                                                                                    
   end;                                                                                                                                 
run;                                                                                                                                    
                                                                                                                                        
/* Create the format from the data set */                                                                                                                                                                                                                                      
proc format library=work cntlin=forest3;                                                                                                
run;                                                                                                                                    
                                                                                                                                        
/* Apply the format to the study values and remove Overall from Study column. */                                                        
/* Compute the width of the box proportional to weight in log scale. */                                                                 
data forest4;                                                                                                                           
   format studyvalue study2value study.;                                                                                                
   drop fmtname type label start end hlo pct;                                                                                           
   set forest3 (where=(studyvalue &amp;gt; 0)) nobs=nobs;                                                                                      
                                                                                                     
  /* Compute marker width */
    c=0.5; /* Factor to adjust absolute marker width */
   x1=oddsratio - c*weight;
   x2=oddsratio + c*weight;
  
                                                                                                   
   /* Compute top and bottom offsets */                                                                                                    
   if _n_ = nobs then do;                                                                                                                  
      pct=0.75/nobs;                                                                                                                        
      call symputx("pct", pct);                                                                                                             
      call symputx("pct2", 2*pct);                                                                                                          
      call symputx("count", nobs);                                                                                                          
   end;                                                                                                                                    
run;                                                                                                                                    
                                                                                                                                        
ods listing close;                                                                                                                      
ods html image_dpi=100 path="." file='sgplotforest.html';                                                                               
ods graphics / reset width=600px height=400px imagename="Forest_Plot_Vector" imagefmt=gif;                                              
                                                                                                                                        
title "Outcome variable";                                                                                      
title2 h=8pt 'Hedges G and 95% CI';                                                                                                   
                                                                                                                                        
proc sgplot data=forest4 noautolegend;                                                                                                  
   scatter y=study2value x=oddsratio / markerattrs=graphdata2(symbol=diamondfilled size=10);                                            
   scatter y=studyvalue x=oddsratio / xerrorupper=ucl2 xerrorlower=lcl2 markerattrs=graphdata1(symbol=squarefilled size=0);             
   vector x=x2 y=studyvalue / xorigin=x1 yorigin=studyvalue lineattrs=graphdata1(thickness=8) noarrowheads;                             
   scatter y=studyvalue x=or / markerchar=oddsratio x2axis;                                                                             
   scatter y=studyvalue x=lcl / markerchar=lowercl x2axis;                                                                              
   scatter y=studyvalue x=ucl / markerchar=uppercl x2axis;                                                                              
   scatter y=studyvalue x=wt / markerchar=weight x2axis;                                                                                                                                                                     
   refline 0 / axis=x lineattrs=(pattern=shortdash) transparency=0.5;                                                              
   inset '           Favours Sham'  / position=bottomleft;                                                                             
   inset 'Favours Active'  / position=bottom;                                                                                           
   xaxis offsetmin=0 offsetmax=0.35 min=-2 max=2 minor display=(nolabel) ;                                                 
   x2axis offsetmin=0.7 display=(noticks nolabel);                                                                                      
   yaxis display=(noticks nolabel) offsetmin=0.1 offsetmax=0.05 values=(1 to &amp;amp;count by 1);                                              
run;                                                                                                                                    
                                                                                                                                        
ods html close;                                                                                                                         
ods listing;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2015 12:06:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-make-forest-plot-rectangles-into-squares/m-p/238491#M8645</guid>
      <dc:creator>j4ne</dc:creator>
      <dc:date>2015-12-09T12:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to make forest plot rectangles into squares</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-make-forest-plot-rectangles-into-squares/m-p/238495#M8647</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could just overlay another scatter, see example:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/graphicallyspeaking/2012/05/28/bivariate-response-graph/" target="_blank"&gt;http://blogs.sas.com/content/graphicallyspeaking/2012/05/28/bivariate-response-graph/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2015 13:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-make-forest-plot-rectangles-into-squares/m-p/238495#M8647</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-09T13:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to make forest plot rectangles into squares</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-make-forest-plot-rectangles-into-squares/m-p/238497#M8648</link>
      <description>&lt;P&gt;What version of SAS are you using?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2015 13:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-make-forest-plot-rectangles-into-squares/m-p/238497#M8648</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2015-12-09T13:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to make forest plot rectangles into squares</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-make-forest-plot-rectangles-into-squares/m-p/238544#M8650</link>
      <description>&lt;P&gt;With SAS 9.3, you can use the GTL code linked by RW9. &amp;nbsp;SG Scatter plot may not support this option.&lt;/P&gt;
&lt;P&gt;With SAS 9.3, HighLow plot can be used to show the weight as the marker length, but with constant width.&lt;/P&gt;
&lt;P&gt;If you must do this with SGPLOT, some people have used multiple overlaid scatter plot statements, each with its own marker size.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2015 17:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-make-forest-plot-rectangles-into-squares/m-p/238544#M8650</guid>
      <dc:creator>Jay54</dc:creator>
      <dc:date>2015-12-09T17:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to make forest plot rectangles into squares</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-make-forest-plot-rectangles-into-squares/m-p/238613#M8658</link>
      <description>Using SAS 9.4&lt;BR /&gt;&lt;BR /&gt;Thanks - these solutions may be beyond my expertise - have decided to edit it after the fact in Paint. Actually looks reasonably okay, surprisingly.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Dec 2015 01:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-make-forest-plot-rectangles-into-squares/m-p/238613#M8658</guid>
      <dc:creator>j4ne</dc:creator>
      <dc:date>2015-12-10T01:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to make forest plot rectangles into squares</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-make-forest-plot-rectangles-into-squares/m-p/238950#M8678</link>
      <description>&lt;P&gt;One of the classic references on good practices in statistical graphics,&amp;nbsp;&lt;A href="http://www.edwardtufte.com/tufte/books_vdqi" target="_blank"&gt;&lt;EM&gt;The Visual Display of Quantitative Information&lt;/EM&gt;&amp;nbsp;(2nd ed.) by Edward Tufte&lt;/A&gt;,&amp;nbsp;recommends: "The number of information-carrying (variable) dimensions depicted should not exceed the number of dimensions in the data." (p. 71).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to this principle&amp;nbsp;it would be&amp;nbsp;better to represent the weights by the lengths of rectangles (of fixed height), as you've done it already, rather than by the areas of squares. (E. Tufte shows a graph with circles whose sizes represent city populations as a bad example.) Indeed, it's easier for the human eye to recognize that one rectangle is, e.g., twice as long as another rectangle than to see that one square has twice the area of another square (i.e. a side length that is 1.4142... times as large).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to&amp;nbsp;the confidence interval of the overall population, I would depict it in a similar way as the others, maybe with thicker lines or in a different color. With&amp;nbsp;a (slightly) stretched diamond it might be less&amp;nbsp;obvious that the diamond width has that particular meaning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get rid of the colors you could add&amp;nbsp;&lt;FONT face="courier new,courier"&gt;style=journal&lt;FONT face="arial,helvetica,sans-serif"&gt; after&lt;/FONT&gt; ods html&lt;FONT face="arial,helvetica,sans-serif"&gt;. If you want to fine-tune the grey scales (cf.&amp;nbsp;&lt;A href="http://www.amadeus.co.uk/sas-training/tips/6/1/99/50-shades-of-grey.php" target="_blank"&gt;http://www.amadeus.co.uk/sas-training/tips/6/1/99/50-shades-of-grey.php&lt;/A&gt;), I'm sure we could find a way to do this, too.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 17:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-make-forest-plot-rectangles-into-squares/m-p/238950#M8678</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-12-11T17:45:04Z</dc:date>
    </item>
  </channel>
</rss>

