- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
I am using sgplot to create heat-maps to present data form a table.
It is a great functionally, but I am struggling with the colour scale for the heat map.
Basically, i am generating several heat maps, based on data from a table, the min and max for the data in each heat map are slightly different, resulting in the colour scale (autogenerated by SGPLIT) being different between the different heat maps, and hence the user cannot appreciate the difference easily.
TO illustrate this, see the following code:
* Generate a table with random numbers;
Data have;
do a= 1 to 3;
do i=1 to 5;
L=1;
o=floor(rand('Uniform')*10);
output;
end;
output;
end;
do a= 1 to 3;
do i=1 to 5;
L=2;
o=floor(rand('Uniform')*5)+2;
output;
end;
output;
end;
run;
*Generate heat-maps;
proc sgplot data=have;
heatmapparm x=a y=i colorresponse=o / outline discretex colormodel=ThreeColorRamp;
text x=a y=i text=o / textattrs=(size=10pt) strip;
by L ;
gradlegend;
run;
you will notice that the code above generates two heat maps but that cells containing the same number (say 6) in the two heat maps have different colour shades.
Is there a way to (force) standardise the colour scale across the heat maps?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How about this one ?
Data have; call streaminit(12345678); do a= 1 to 3; do i=1 to 5; L=1; o=floor(rand('Uniform')*10); output; end; output; end; do a= 1 to 3; do i=1 to 5; L=2; o=floor(rand('Uniform')*5)+2; output; end; output; end; run; proc sql noprint; select min(o),max(o) into :min,:max from want; quit; proc template; define statgraph cal_heatmap; begingraph ; entrytitle "xxxxxxxxxx"; rangeattrmap name="rmap"; range &min- &max / rangecolormodel=ThreeColorRamp; endrangeattrmap; rangeattrvar attrmap="rmap" attrvar=cvar var=o; layout overlay ; heatmapparm x=a y=i colorresponse=cvar/ name="heatmap" xgap=1 ygap=1; scatterplot x=a y=i/ MARKERCHARACTER=o markerattrs=(size=20pt) ; *continuouslegend "heatmap" ; endlayout; endgraph; end; run; proc sgrender data=have template=cal_heatmap; by l; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Have you tried using the COLORGROUP variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks @ChrisNZ
Very hepful indded.
I only needed to read the documentation in more details, I found the rattrmap option seems to give control over how the colours are assigned.
data myrattrmap;
retain id "myID";
length min $ 5 max $ 5;
input min $ max $ color $ altcolor $;
datalines;
_min_ 4 purple purple
4 6 gold gold
6 _max_ green green
;
run;
proc sgplot data=have rattrmap=myrattrmap;
heatmapparm x=a y=i colorresponse=o / rattrid=myID outline discretex colormodel=ThreeColorRamp;
text x=a y=i text=o / textattrs=(size=10pt) strip;
by L ;
gradlegend;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How about this one ?
Data have; call streaminit(12345678); do a= 1 to 3; do i=1 to 5; L=1; o=floor(rand('Uniform')*10); output; end; output; end; do a= 1 to 3; do i=1 to 5; L=2; o=floor(rand('Uniform')*5)+2; output; end; output; end; run; proc sql noprint; select min(o),max(o) into :min,:max from want; quit; proc template; define statgraph cal_heatmap; begingraph ; entrytitle "xxxxxxxxxx"; rangeattrmap name="rmap"; range &min- &max / rangecolormodel=ThreeColorRamp; endrangeattrmap; rangeattrvar attrmap="rmap" attrvar=cvar var=o; layout overlay ; heatmapparm x=a y=i colorresponse=cvar/ name="heatmap" xgap=1 ygap=1; scatterplot x=a y=i/ MARKERCHARACTER=o markerattrs=(size=20pt) ; *continuouslegend "heatmap" ; endlayout; endgraph; end; run; proc sgrender data=have template=cal_heatmap; by l; run;