FOCUS AREAS

Graphics

heat maps with discrete axes
Base SAS: Graph Template Language

/* This program requires SAS 9.4 TS Level 1M2 or later */
%let gpath='.';
%let dpi=100;

/** *************
 * This sample uses the Graph Template Language (GTL) to produce two Heat Maps
 * in a two column Lattice Layout. The graph on the left shows  Emerging Issues
 * by date and period in service. The one on the right is a Gene Expression Graph.
 */

proc format;
  value zval 1='Potential Problem'
             2='Emerging Issue'
             other=.;
run;

%let wuMax = 12;

data wu;
  format x date9.;
  format z  zval.;
  keep x y z;
  do i=1 to &wuMax;
    do j=0 to &wuMax - i;
      x=j * 15 + '01Jan2006'd;
      y=put(i, best.);
      z=int(8 * abs(ranuni(0))) + 1;
*     --Set values over 2 to 3, to get more white boxes--;
      if z > 2 then z=.;
        output;
      end;
  end;
run;

/*--Simulate data for Genomic Heat Map--*/
%let genMax = 15;

data genome (keep=gene name val);
  length Gene $12;
  length e s r $3;
  length Name $ 8;
  format val 8.5;
  retain pi 3.1415;

  do i=1 to &genMax;
     e = put (int (max (min (1000* ranuni(0), 999),1) ), z3.0);
     s = put (int (max (min (1000* ranuni(0), 999),1) ), z3.0);
     r = put (int (max (min (1000* ranuni(0), 999),1) ), z3.0);
     gene='E' || e || 'S' || s || 'R' || r;
     do j = 1 to &genMax;
       Name=put (j, 3.);
       val = max (min (2*(1+cos(j*PI/23+0.3*ranuni(0)))
             + 2*(1+sin((i+3)*PI/15+0.7*ranuni(0))), 9),1);
       output;
    end;
  end;
run;

/*--Merge datasets to make both heat maps in one graph--*/
data grid;
  merge wu genome;
run;

proc template;
  define statgraph heatmaps;
    begingraph / designwidth=800px designheight=400px subpixel=on;
      entrytitle "Heat Maps with Discrete Axes";
      layout lattice / columns=2 columngutter=5%;
        column2Headers;
          entry "Emerging Issues" / textattrs=GraphlabelText;
          entry "DNA Microarray" / textattrs=GraphlabelText;
        endColumn2Headers;

        layout overlay / xaxisopts=(type=time label='Build Period')
            yaxisopts=(label='Periods in Service') aspectRatio=1.0;
          heatMapParm x=x y=y colorGroup=z / name='heat1' xGap=1px yGap=1px
            includeMissingColor=false;
          discretelegend 'heat1' / location=outside halign=center down=1
            valign=bottom pad=1px;
        endlayout;

        layout overlay / xaxisopts=(label='Samples'
            discreteopts=(tickvaluefitpolicy=thin)) aspectRatio=1.0;
          heatMapParm x=name y=gene colorResponse=val / xGap=1px yGap=1px												
            colormodel=threecolorramp name='heat2';
          continuouslegend 'heat2' / orient=vertical location=outside halign=right;
        endlayout;
      endlayout;
    endgraph;
  end;
run;

proc template;
define Style HeatMapStyle; 
  parent = styles.harvest;
  style GraphFonts from GraphFonts                                                      
    "Fonts used in graph styles" /                                                       
      'GraphTitleFont' = (", ",10pt,bold)
      'GraphFootnoteFont' = (", ",8pt)
      'GraphLabelFont' = (", ",7pt) 
      'GraphValueFont' = (", ",5pt)
      'GraphDataFont' = (", ",5pt)              
  ;
  style GraphColors from graphcolors /
    "gcdata1" = cxaf1515
    "gcdata2" = cxeabb14
    "gcdata3" = cxffffff

    "gramp3cend" = cxaa081b                                              
    "gramp3cneutral" = cx000000                                          
    "gramp3cstart" = cx1ba808
  ;
end;
run;

ods _all_ close;
ods listing gpath=&gpath image_dpi=&dpi style=heatMapStyle;

ods graphics on / reset imagename='HeatMaps' width=6.93in height=3.14in;
proc sgrender data=grid template=heatmaps;
run;

ods _all_ close;