BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
acuffza
Calcite | Level 5

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;


Metals Correlations.png
1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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 ...;

View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ

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;
acuffza
Calcite | Level 5

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;

Rick_SAS
SAS Super FREQ

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 ...;

acuffza
Calcite | Level 5

That worked perfectly! Thank you so much, Rick!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3463 views
  • 0 likes
  • 2 in conversation