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.
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
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
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.
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."
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.