Skip to content

Instantly share code, notes, and snippets.

@zhilongjia
Created January 23, 2021 12:08
Show Gist options
  • Save zhilongjia/3deace052b2dc9ef43f585d16a72fc97 to your computer and use it in GitHub Desktop.
Save zhilongjia/3deace052b2dc9ef43f585d16a72fc97 to your computer and use it in GitHub Desktop.
visulising the correltion between two views of the same samples
# visulising the correltion between two views of the same samples
# such as the first 4 features in mtcars as 1 view, the others as another view.
# as it not easy to implement using corrplot.
# the resulting figure
![clustering correlation](https://i.ibb.co/LRKsKCC/corrletion-hclust.png])
library(ComplexHeatmap)
data(mtcars)
cor_list <- Hmisc::rcorr(as.matrix(mtcars))
r_mat <- cor_list$r
p_mat <- cor_list$P
r_mat_test <- r_mat[1:4,5:11]
p_mat_test <- p_mat[1:4,5:11]
col_fun = circlize::colorRamp2(c(-1, 0, 1), c("blue", "white", "red"))
Heatmap(r_mat_test, name = "cor", col = col_fun, rect_gp = gpar(type = "none")
, cell_fun=function(j, i, x, y, width, height, fill) {
grid.rect(x = x, y = y, width = width, height = height,
gp = gpar(col = "grey", fill = NA))
grid.circle(x = x, y = y, r = abs(r_mat_test[i, j]) * min(unit.c(width, height)),
gp = gpar(fill = col_fun(r_mat_test[i, j]), col = NA))
grid.text(sprintf(ifelse(p_mat_test[i, j]<0.05, "*", "") ), x, y,
gp = gpar(fontsize = 15))
} )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment