Heatmap with Correlation coefficient

Dear Experts,
I am interested to correlate 2 variables like gene expression and protein expression using Spearman correlation coefficient analysis as depicted in Fig. A ( Int. J. Mol. Sci. 2018 , 19 (12), 3836; IJMS | Free Full-Text | Local and Systemic Cytokine Profiling for Pancreatic Ductal Adenocarcinoma to Study Cancer Cachexia in an Era of Precision Medicine). I searched on the net to see the code for correlation but these codes give the heatmaps with Spearman correlation with same X and Y axis as can be seen in Fig. B. ( ggplot2 : Quick correlation matrix heatmap - R software and data visualization - Easy Guides - Wiki - STHDA.
I need a heatmap showing variables from gene expression data on 1 axis (var 1) and protein expression on other axis (var 2)

as in Fig A.

Thanks in advance for your kind help.

Hi @sandeepvermma,

It's basically a matter of filtering your x and y axes to suite your needs after computing all pair-wise correlations using standard methods (I used corrr here). Here is a simplified example of how the heatmap would look without filtering (similar to Figure B) and after filtering the x and y axis to show different variables on each axis (similar to Figure A). You could rework this code to have all of the gene expression variables on one axis and protein expression on the other.

library(corrr)
library(dplyr)
library(ggplot2)

sp <- 
  mtcars %>% 
  correlate(method = "spearman") %>% 
  stretch()

# Like Figure B
sp %>% 
  ggplot(aes(x, y, fill = r)) +
  geom_tile()

# Filter based on what variables you want on the
# x and y axes for the heatmaps
sp_filtered <- 
  sp %>% 
  filter(
    x %in% c("mpg", "cyl", "disp", "hp", "drat"),
    y %in% c("wt", "qsec", "vs", "am", "gear", "carb")
  )

# Like Figure A
sp_filtered %>% 
  ggplot(aes(x, y, fill = r)) +
  geom_tile()

Thank you so much @mattwarkentin for the solution.
I really wanted this but not getting how :slight_smile:

Thanks & Best Regards
Sandeep

Hello, I was wondering if you've figured out how to generate and add the p-value to the heat map.

Customizable correlation heatmaps in R using purrr and ggplot2 | by Kat Hoffman | Towards Data Science

Hi @cnohra, this link might be helpful.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.