Creating correlation heat maps
In this recipe, we will learn how to make a correlation heat map from a matrix of correlation coefficients.
Getting ready
We will only use the base graphics functions for this recipe. So, just open up the R prompt and type in the following code. We will use the genes.csv
example dataset for this recipe. So, let's first load it:
genes<-read.csv("genes.csv")
How to do it...
Let's make a heat map showing the correlation between genes in a matrix:
rownames(genes)<-genes[,1] data_matrix<-data.matrix(genes[,-1]) pal=heat.colors(5) breaks<-seq(0,1,0.2) layout(matrix(data=c(1,2), nrow=1, ncol=2), widths=c(8,1), heights=c(1,1)) par(mar = c(3,7,12,2),oma=c(0.2,0.2,0.2,0.2),mex=0.5) image(x=1:nrow(data_matrix),y=1:ncol(data_matrix), ...
Get R: Data Analysis and Visualization now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.