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

I want to change the color ramp of my heatmap plot. I make a heatmap plot using a graphical template language. My response variable is in percentage form. So, I want to make the colormodel represent the value between 0 to 100 percent, blue color for low percentage (0% to 10%), white color for 10% to 20%, and red color for more than 20%. But my response variable (colorresponse) is range between 0 to around 20 percent, which caused different output from what I want. The color range follow the response variable's range (0 to 20%). Here is the code I've tried.

 

proc template;
define statgraph training;
begingraph /DESIGNHEIGHT=550px DESIGNWIDTH=650px;
entrytitle 'Heatmap of Digit Check';
layout overlay /yaxisopts=(label="Date" tickvalueattrs=(size=8pt)) xaxisopts=(label="Last Digit" tickvalueattrs=(size=8pt));
heatmapparm y=day x=ld colorresponse=percent / display=all name='percent' colormodel=(blue white red);
scatterplot x=sbp_ld y=day /markercharacter=percent markercharacterattrs=(size=8);
continuouslegend 'percent';
endlayout;
endgraph;
end;
run;

 

proc sgrender data=digit_check template=training;
run;

 

Here is the result.

Doc1-page0001.jpg

 Could anyone help me on this? Thank you for any help you can offer.

 

Regards,

Mifta

1 ACCEPTED SOLUTION
2 REPLIES 2
mifta
Calcite | Level 5
Hi Ksharp, Thank you for this. I already followed the steps in the articles you sent, but I found a problem when trying to use the custom color ramp in colormodel= option in the hetmapparm. But thankfully it already resolved. Here is the full script that I use, in case other people need it.

proc template;
define statgraph training;
begingraph/DESIGNHEIGHT=500px DESIGNWIDTH=550px;
rangeattrmap name="ResponseRange";
range MIN - 10 / rangeColorModel=(blue lightblue);
range 10 < - 20 / rangeColorModel=(lightblue white lightred);
range 20 < - MAX / rangeColorModel=(lightred red);
endrangeattrmap;
rangeattrvar var=percent /* specify response variable in data set */
attrmap="ResponseRange" /* specify custom color ramp */
attrvar=RangeVar; /* alias for this variable/ramp combination */
entrytitle "Heat Map";
layout overlay /yaxisopts=(label="Employee" tickvalueattrs=(size=8pt)) xaxisopts=(label="Last Digit" tickvalueattrs=(size=8pt));
heatmapparm y=employee x=last_digit colorresponse=RangeVar / display=all name='percent';
scatterplot x=last_digit y=employee /markercharacter=percent markercharacterattrs=(size=6.5);
continuouslegend 'percent' / title='Percentage';
endlayout;
endgraph;
end;
run;

Regards,
Mifta

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1498 views
  • 2 likes
  • 2 in conversation