Calendar Heatmaps in GTL

Calendar Heatmaps are an interesting alternative view of time-series data. The measured value is displayed as color mapped cells in a calendar. Calendar Heatmaps can be easily created with SAS 9.3 using just the HEATMAPPARM, SERIESPLOT and BLOCKPLOT statements in GTL and some simple data manipulation.
The example below shows the number of traffic fatalities in the US[1] during 2008. The effects of weekends and holidays can be clearly seen in this graph.

Calendar Heatmap of US Traffic Fatalities in 2008

proc template;
  define statgraph cal_heatmap;
    begingraph / designheight=210 designwidth=1200;
	  entrytitle 'Traffic Fatalities in the US during 2008';
	  rangeattrmap name="rmap";
		range 0 - max / rangecolormodel=(white cxeeeeaa red);
	  endrangeattrmap;
	  rangeattrvar attrmap="rmap" attrvar=cvar var=fatalities;
	  layout overlay / walldisplay=none 
                   xaxisopts=(display=none) 
                   yaxisopts=(display=(tickvalues) reverse=true 
                                  linearopts=(tickvaluelist=(1 2 3 4 5 6 7)) );
  	      heatmapparm x=week y=weekday colorresponse=cvar / 
                                 name="heatmap" xgap=1 ygap=1;
	      seriesplot x=wk y=wd / connectorder=xvalues 
                                              break=true 
                                              lineattrs=(color=black) 
                                              primary=true;
	      innermargin / align=bottom;
	          blockplot x=prevwk block=month / 
                               valuehalign=center display=(values);
	      endinnermargin;
	      continuouslegend "heatmap" ;
	  endlayout;
    endgraph;
  end;
run;
 
proc sgrender data=combined template=cal_heatmap;
run;

Complete SAS program

The example above was created by generating a day of the week and week of the year value from the date value and using those columns as the X and Y values on the HEATMAPPARM. The month boundaries are computed from the input date variable and rendered using the SERIESPLOT statement and the month labels are drawn using a BLOCKPLOT statement.

When working with financial data, weekly trends as well as the values at the end of month, quarter or year can also be more easily observed on a Calendar Heatmap. The example below shows the % daily change in the Dow Jones composite index during 1988.

Calendar Heatmap of Dow Jones Composite Index in 1988

proc template;
  define statgraph cal_heatmap;
    begingraph / designheight=210 designwidth=1200;
	  entrytitle 'Calendar Heatmap of % daily change of the DOW Jones composite index in 1988';
	  rangeattrmap name="rmap";
	    range min - 0 / rangecolormodel=(darkred red yellow);		
	    range 0 - max / rangecolormodel=(yellow green darkgreen);
 
	  endrangeattrmap;
	  rangeattrvar attrmap="rmap" attrvar=cvar var=percent;
	  layout overlay / walldisplay=none 
                   xaxisopts=(display=none) 
                   yaxisopts=(display=(tickvalues) reverse=true 
                                  linearopts=(tickvaluelist=(1 2 3 4 5 6 7)) );
              heatmapparm x=week y=weekday colorresponse=cvar / 
                                 name="heatmap" xgap=1 ygap=1;
              seriesplot x=wk y=wd / connectorder=xvalues break=true 
                                              lineattrs=(color=black) 
                                              primary=true;
              innermargin / align=bottom;
                  blockplot x=prevwk block=month / 
                               valuehalign=center display=(values);
              endinnermargin;
              continuouslegend "heatmap" / valuecounthint=3;
	  endlayout;
	endgraph;
  end;
run;
 
proc sgrender data=combined template=cal_heatmap;
run;

Complete SAS program

As in the first example, the day of the week and the week of the year were computed and used for the X & Y values on the HEATMAPPARM. A RANGEATTRMAP is used with the COLORRESPONSE option to clearly represent the positive and negative changes in the Dow Jones composite index. The empty cells correspond to days where the Stock Exchange was closed.

[1] Data Source: http://www-fars.nhtsa.dot.gov

tags: CalendarHeatmap, GTL, Heatmap, ODS Graphics

4 Comments

  1. Richard Hoskins
    Posted December 8, 2011 at 8:15 pm | Permalink

    Will these heatmaps run in 9.2?

  2. Posted February 13, 2012 at 6:30 pm | Permalink

    You can also look at "Stretching the Bounds of SAS/GRAPH® Software" ... http://www2.sas.com/proceedings/sugi30/137-30.pdf.

    There are also examples at http://www.albany.edu/~msz03/temps.html together with a link to daily temperature data for US and world cities (nice for practice with heat maps)

One Trackback

  1. By Beer, daipers and heat map - Graphically Speaking on February 13, 2012 at 12:04 am

    [...] can display the heat map with a ColorResponse rather than ColorGroup.  An example of this is the Calender Heatmap posted earlier in this blog by Pratik [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <p> <pre lang="" line="" escaped=""> <q cite=""> <strike> <strong>