In this recipe, we will learn how to make a correlation heat map from a matrix of correlation coefficients.
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")
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), z=data_matrix,xlab="",ylab="",breaks=breaks, col=pal,axes=FALSE) text(x=1:nrow(data_matrix)+0.75, y=par("usr")[4] + 1.25, srt = 45, adj = 1, labels = rownames(data_matrix), xpd = TRUE) axis(2,at=1:ncol(data_matrix),labels...