BookmarkSubscribeRSS Feed
gmgrosse
Fluorite | Level 6

Dear all,

 

I try to create a Heatmap of inter-biomarker correlations using PROC SGPLOT. However,  I repeatedly failed to adjust the color scale. I would like to define white as the "0"-level of Pearson's r, and blue for negative and red for positive values, as I think that this would be the intuitive Interpretation. See the code below. I tried to define colormodel(STARTCOLOR "-1") etc. but this was not helpful at all.

 

I am grateful for any suggestions.

 

Thank you and kind regards

 

proc sgplot data=CorrLong noautolegend;

heatmap x=Variable y=CorrelationID / colorresponse=Correlation name="nope1" discretex discretey x2axis colormodel=ThreeColorRamp;

text x=Variable y=CorrelationID text=p_value / textattrs=(size=5pt) x2axis name='nope2';

label correlation='Pearson Correlation';

yaxis reverse display=(nolabel);

x2axis display=(nolabel);

gradlegend;

run;

 

7 REPLIES 7
ballardw
Super User

Data would be helpful as we have no idea what the distribution or actual range of your Correlation variable may be.

If you want specific ranges to display in certain colors look at the RATTRMAP data set option where you provide range of values and colors.

 

Example (obviously untested as no data provided)

data clrresp;
   retain id "myid";
   length min $ 5 max $ 5;
   input min $ max $ color $ altcolor $ excludemax excludemin;
datalines;
_min_  0   blue   blue   1  0
0      0   white  white  0  0
0   _max_  red    red    0  1
;

proc sgplot data=CorrLong noautolegend rattrmap=clrresp;
   heatmap x=Variable y=CorrelationID / colorresponse=Correlation name="nope1" discretex
                                        discretey x2axis rattrid=myid;
   text x=Variable y=CorrelationID text=p_value / textattrs=(size=5pt) x2axis name='nope2';
   label correlation='Pearson Correlation';
   yaxis reverse display=(nolabel);
   x2axis display=(nolabel);
   gradlegend   ;

run;
gmgrosse
Fluorite | Level 6

Thank you, but is there also a solution within PROC SGPLOT?

DanH_sas
SAS Super FREQ

The solution that @ballardw gave is the best SGPLOT solution. The range attribute data set is used by SGPLOT (via the RATTRMAP and RATTRID options) to control how colors are applied to continuous ranges, such as COLORRESPONSE. By using the _min_/_max_ keywords as he did, this data set definition will reflect any COLORRESPONSE data around a 0 inflection point, regardless of data range. What is your concern about this approach?

ballardw
Super User

@gmgrosse wrote:

Thank you, but is there also a solution within PROC SGPLOT?


Provide data and an image of what you expect a result to look like for that example data and maybe.

What is possible with any graph is very dependent on the data available. For example, if I have exactly two x,y pairs I cannot make much of a polygon shape, there just are not enough points. 

 

Options depend on desired appearance. The only thing you provided along those lines were Heatmap and blue, white, red. Not much to go on, especially without data.

gmgrosse
Fluorite | Level 6

Thanks very much for your help. Unfortunately, I cannot upload my raw data since these are unpublished so far... Basically, I intend to plot the results from inter-biomarker pearson's correlation. Here is the result of what I previously did: 

gmgrosse_0-1615396034048.png

What is intended is the same map, but white shall be coded as 0 and the scale ranging from -1 to +1.

Thanks again

 

ballardw
Super User

Maybe an RATTRMAP set like this:

data clrresp;
   retain id "myid";
   length min $ 5 max $ 5;
   input min $ max $ colormodel1 $ colormodel2 $ excludemax excludemin;
datalines;
_min_  0   darkblue   white   1  0
0      0   white  white  0  0
0   _max_  white    darkred    0  1
;

Using the colormodel variables then a scale is created between the values. This should shade the values close to -1 (if your data doesn't have values below that use -1 instead of _min_ , and 1 instead of _max_) as darkblue shading towards white as the values get closer the zero, and white toward darkred from 0 to 1.

You can provide a single 3 color ramp style object but the rules for which exact value gets the middle color may not yield what you expect/ want with non-symetrical value ranges.

 

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1602 views
  • 6 likes
  • 4 in conversation