I'm using SAS 14.1. I'm making a heat map of Spearman correlations. The x-axis and the y-axis both list the same 14 metals and the color indicates a metal's correlation with another metal. The figure looks good, but I want to change the color scale. Right now, the correlations range from about -.6 to 1 (1 meaning that the metal is perfectly correlated with itself) and the colors range from dark blue to white to dark red. Since 0 isn't right in the middle of this range, a correlation of 0 is indicated by a pale blue, but I would like white to represent 0 since that makes the most intuitive sense. Does anyone know how I can "slide" the color scale down this way so that 0 is white? My code is below and I attached the resulting heat map.
proc template;
define statgraph heatmapparm;
begingraph;
layout overlay;
heatmapparm x=metal_1 y=metal_2 colorresponse=spearman_corr /
name="heatmapparm";
continuouslegend "heatmapparm" / location=outside valign=bottom;
endlayout;
endgraph;
end;
run;
proc sgrender data=final template=heatmapparm;
run;
You also need to use the RANGEATTRVAR statement to define the variable that is the response. The following is untested:
rangeattrmap name='ThreeColor';
range -1-1 / rangecolormodel=ThreeColorRamp;
endrangeattrmap;
rangeattrvar attrvar=rangevar var=spearman_corr attrmap=ThreeColor;
...
heatmapparm colorresponse=rangevar ...;
the easiest approach is the user the RANGE option to set the range of the colorramp to [-1, 1]. Look at the doc for the RANGEATTRMAP statement. the syntax will look something like this:
rangeattrmap name='ThreeColor';
range -1 - 1 / rangecolormodel=ThreeColorRamp;
endrangeattrmap;
Thank you, Rick. I altered my code, ran it and didn't see an error in the log, but the result looked the same. Did I get something about the syntax wrong?
proc template;
define statgraph heatmapparm;
begingraph;
rangeattrmap name="ThreeColor";
range -1-1 / rangecolormodel=ThreeColorRamp;
endrangeattrmap;
layout overlay;
heatmapparm x=metal_1 y=metal_2 colorresponse=spearman_corr /
name="heatmapparm" /*xbinaxis=false ybinaxis=false*/;
continuouslegend "heatmapparm" / location=outside valign=bottom;
endlayout;
endgraph;
end;
run;
You also need to use the RANGEATTRVAR statement to define the variable that is the response. The following is untested:
rangeattrmap name='ThreeColor';
range -1-1 / rangecolormodel=ThreeColorRamp;
endrangeattrmap;
rangeattrvar attrvar=rangevar var=spearman_corr attrmap=ThreeColor;
...
heatmapparm colorresponse=rangevar ...;
That worked perfectly! Thank you so much, Rick!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.