BookmarkSubscribeRSS Feed
mhudec24
Calcite | Level 5

Im creating a heat map in SAS using proc sgplot to provide a visual for the % gain/loss within several deparments within different divisions. However, I am running into a problem with the y-scale. Being a percentage, I would ideally want positive numbers to be green, negative numbers be red, and neutral numbers be white. I have this color scale set properly, but the scale has .03 as the median instead of 0. Therefore, I am getting positive numbers (.01 and .02) to be red, while they should be green. Is there a way to adjust the Y scale and make 0 white, any positive number green, and any negative number red? I've tried using the ybinstart=-.05, but it is not changing my scale at all. I have attached a picture of the current scale that is incorrect. I appreciate your help. 

3 REPLIES 3
Rick_SAS
SAS Super FREQ

I would call this the "Z scale" rather than the Y scale. What you want is a symmetric red-white-green color ramp that is centered on 0.

 

There are two ways to handle this situation. Range attribute maps appeared in 9.4M3. You can define a range attribute map for a symmetric data range. See

GTL overview: https://blogs.sas.com/content/graphicallyspeaking/2013/04/14/attributes-map-3-range-attribute-map/

SGPLOT usage: https://blogs.sas.com/content/graphicallyspeaking/2017/06/26/advanced-ods-graphics-range-attribute-m...

Your data map might look like this 

ID    ColorModel1 ColorModel2 Min   Max

myID  red         white       -0.07 0

myID  white       green        0    0.07

 

The simpler way (and the way I'd suggest if you don't have a recent version of SAS) is to prepend "fake data" to your data set. See

https://blogs.sas.com/content/iml/2016/02/17/include-and-order-categories-in-legends.html

In this case, if your variables are X, Y, and Z, you can prepend the following data

X Y  Z

. . -0.07

. .  0.07

 

This "data" will force PROC SGPLOT to think that the range of Z is [-0.07, 0.07], but the missing values in X and Y prevent the procedure from including those observations in the graph.

mhudec24
Calcite | Level 5

Perfect! Thank you. I also had another question. I was interested in changing the size of the boxes dependant upon a variable. The larger the number, the larger the box, and vice versa. Is there a way to do this?

Rick_SAS
SAS Super FREQ

I think the HEATMAP and HEATMAPPARMS statements provide for a uniform grid of X-Y values. However, you might look into using a bubble plot instead of a heat map. The bubble plot is designed to have the marker sizes that vary according to the value of some response. If you use a bubble plot, you might have to bin the data yourself. For examples, see "counting observations in two-dimensional bins" and "Designing a quantile bin plot."  For bubble plot basics, see "Getting started with a bubble plot."

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
  • 3 replies
  • 2009 views
  • 0 likes
  • 2 in conversation