Calendar Heatmaps in GTL

9

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

Share

About Author

Pratik Phadke

Software Developer

Pratik Phadke is a Senior Developer in the Data Visualization group at SAS Institute. He has worked on interactive visualization components used in various SAS products, including Enterprise Miner and Forecast Studio as well as ODS Graphics. He received a master's degree in Computer Science from the University of Maryland, Baltimore County.

Related Posts

9 Comments

  1. Pingback: Beer, daipers and heat map - Graphically Speaking

  2. Pratik, can you please share the structure of the data file which you used to create a calendar heatmap in SAS? (Eg. variable names and types in the Fatalities file and perhaps how you prepared the file for graphing.)

  3. Dear Sanjay, how would we modify the code so I can get an annual plot (multiple years with multiple plots)? thanks!

Leave A Reply

Back to Top