BookmarkSubscribeRSS Feed
Kels123
Quartz | Level 8

Hello,

I am doing a study looking at correlations between multiple cytokines. I found code to let me graph a heatmap of the correlation matrix, but I am having trouble making modifications to the heatmap.

 

1.) Specifically, I would like to be able to change the color, i.e. instead of white = -1 and dark blue = +1, I was hoping to use a different color for <1 values to make the correlation values more obvious.

 

2.) In addition, I was hoping to reorder the cytokines so that the strongest and weakest correlations are next to each other to make the data more interpretable.

 

3.) I also in a perfect world would be able to re-label the cytokine names so that show up prettier (e.g. with hyphens instead of underscores, etc).

 

Here is my code below. The last paragraph of code is what I was trying to use to modify the order of the cytokines (labeled/* load the module for single-link clustering */). I am also attaching images of what my heatmaps currently look like.

 

Any guidance would be greatly appreciated!

 

/*HEAT MAP CORRELATION MATRIX FOR ALL SAMPLES*/

TITLE "Correlation Matrix for All Samples";

proc iml;

/* create correlation matric for variables in alphabetical order */

varNames = {'IL_28A''IL_6''IL_8''IL_7''IFN_Beta''IL_10''CCL2''IL_1b''IFN_g''CCL3''CCL22''CCL4''IL_4'

/*'IL_17A' 'IL_2'*/ 'CXCL9' 'IL_5' 'TNFRI' 'IL12p70' 'CCL17' 'TNFa' 'IL_28B' 'CXCL10' /*'IL_23'*/};

/*Sample_cat = sample_cat;

Dz_severity_binary2 = Dz_severity_binary2;*/

use Gawlib.cytokine_80121 where (Dz_severity_binary2 >=0) ;  

read all var varNames into Y where (sample_cat>=1) ;  

read all var varNames into Y where (sample_cat>=1) ;  

close;

corr = corr(Y, "Spearman");

 

call HeatmapCont(corr) xvalues=varNames yvalues=varNames 

            colorramp=colors range={-1.01 1.01} 

            title="Correlation Matrix: Cytokine levels for all samples";

 

/* load the module for single-link clustering */

load module=(SingleLinkCluster);

permutation = SingleLinkCluster( corr );  /* permutation of 1:p */

V = varNames[permutation];                /* new order for variables */

R = corr[permutation, permutation];       /* new order for matrix */

call HeatmapCont(R) xvalues=V yvalues=V 

            colorramp=colors range={-1.01 1.01} 

            title="Correlation: Variables in Clustered Order";

2 REPLIES 2
Ksharp
Super User

Why not post it at IML forum and @Rick_SAS  is there .

and also could check 

call HeatmapDist()

Rick_SAS
SAS Super FREQ

It looks like you found the blog post the describes how to reorder the variables so that highly correlated variables are nex.... Use that article to do (2).

 

For (1), use the COLORRAMP= option and specify a valid color ramp. The documentation for the HEATMAPCONT subroutine describes four ways to define color ramps. For example, the blog post uses

colors = palette("BrBg", 7);

As explained in the documentation of the HEATMAPCONT subroutine, you can often accomplish (3) by defining short labels and using the XVALUES= and YVALUES= keywords to specify the labels. FOr example, here is a modification of the example from the blog post for which I use custom labels:

proc iml;
/* create correlation matric for variables in alphabetical order */
varNames = {'Cylinders' 'EngineSize' 'Horsepower' 'Invoice' 'Length' 
            'MPG_City' 'MPG_Highway' 'MSRP' 'Weight' 'Wheelbase'};
use Sashelp.Cars;  read all var varNames into Y;  close;
corr = corr(Y);
colors = palette("BrBg", 7);

/* define custom labels (keep them short) */
labels = {'Cyl-10' 'EngSize-02' 'HP-001A' 'Invoice' 'Length' 
            'MPG (City)' 'MPG (Highway)' 'MSRP' 'Weight' 'Wheelbase'};

call HeatmapCont(corr) xvalues=varNames yvalues=varNames 
            colorramp=colors range={-1.01 1.01} 
            xvalues=labels yvalues=labels
            title="Correlation Matrix: Variables in Alphabetical Order";


sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 679 views
  • 1 like
  • 3 in conversation