Hi R community,
I have a question about the creation of a heatmaps in combination with the cluster analysis (see the attached figure).
Somebody know the script and packages to use about this graphs?
Hello Jo,
As far as I know these are typically produced with a couple of packages together. You can have a look here at how to create it: https://www.datanovia.com/en/lessons/heatmap-in-r-static-and-interactive-visualization/
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.
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.