 # 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; https://doi.org/10.3390/ijms19123836). 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.

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 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