Hi Jo,
The link that GreyMerchant posted is definitely a good resources when you start with heatmaps in r.
I especially like the pheatmap package which is mentioned there. It is quite good at producing pretty heatmaps, including clustering and dendrograms. It accepts numeric matrices as input (e.g. a correlation matrix), you can supply an extra distance matrix, and it includes several methods for the clustering as well as a whole bunch of other options.
The example you are showing actually looks like it could have been created with pheatmap, but without seeing the data, I cannot tell you how your example was made.
However, a general approach to a heatmap could be something like this:
# create a sample matrix
mat<-matrix(runif(100,min=0,max=100),nrow=10,ncol=10,dimnames = list(letters[1:10],LETTERS[1:10]))
# create data frames with sample annotations
annotCol<-data.frame(S=rep(c("sample","control"),each=5),row.names = LETTERS[1:10])
annotRow<-data.frame(G=paste0("G",1:10),row.names = letters[1:10])
# create corrolation matrix and compute distance
corMat<-cor(mat,method = "pearson")
distMat<-as.dist(1-corMat)
dimnames(corMat)<-list(letters[1:10],LETTERS[1:10])
#plot the heatmap
pheatmap::pheatmap(corMat,
clustering_distance_cols = distMat,
clustering_distance_rows = distMat,
annotation_row = annotRow,
annotation_col = annotCol)
Of course you will have to decided the parameters for computing corrolation, distance and for clustering based on your own data, the code above is just a simplified demonstration of the pheatmap function.