I have a data frame of omics data. Gene ids in rows (931), and samples in columns (15).
> dim(my_data) # (rows columns)
[1] 931 16
I created heatmap using library(gplots)
cn=colnames(gdf1)[c(13:15,1:12)]
col <- colorRampPalette(c("red","yellow","darkgreen"))(30)
heatmap.2(as.matrix(gdf1[,cn]),
dendrogram = "row",
Colv = FALSE,
Rowv = TRUE,
scale = "none",
col = col,
key = TRUE,
density.info = "none",
key.title = NA,
key.xlab = "Abundance",
trace = "none",
margins = c(7, 15))
However, in the heatmap, I see only few genes. Since it has 900 ish genes. How can I export what are the clustered genes in each cluster in the same order as in the heatmap?
Also, how can I reduce the size of colorkey?
Thank you.
Thanks a heap, Kevin :) This is helpful. BTW, I did try this now. Since I have ~900 genes. it's too much for plotting in a diagram. Gow can I export these clustered genes to a csv file, in the same order as showing in the dendrogram?.
Hey, you just mean like this ? -
Remember that the order is bottom-to-top
Thanks Kevin, This also useful. I am looking into much more detailed out put. Not sure if this is possible in heatmap2.
For selected cutoff (e.g. distance = 40), how can we separate the list of genes n that cluster?
something like this, How to see the grouping of genes for each cluster in the o/p?
Ah - I see. In that case, it is easier to create your own dendrogram outside
heatmap.2()
, and then usecutree()
on that:Create random data
Cluster the genes (rows) manually
Plot the heatmap
They are the same.
Cut the dendrogram into groups or specify a height for the cut-off:
----------------------
You should be able to output these lists as per the order in the heatmap / dendrogram to (the indices are stored in
out$rowInd
)Thanks a heap, Kevin :) Appreciate.
Hi Kevin:
Is it possible to do the same in ComplexHeat map. I put the above command in Heatmap it throws out a message:"
I read the manual of complexheatmap(split by dendrogram part), but does not understand fully how it can be done in practice.
For ComplexHeatmap, it's a bit different. I think that you want to do this:
?
Or is this what you want to do:
?
Hi Kevlin:
Thank you for the link, when I tried to re-do what the code instructed, but I got an error I can't understand. My matrix contains 5 columns, column 1 to column4 are the counts at different stages, while column5 are the differences between colum3 and column1 (which is diff=column3-colum1). Rowname of the matrix is the gene.
I use
row_clust <- hclust(dist(mydat_2, method = 'euclidean'), method = 'ward.D2')
to do the clustering manually. And I useTo draw the Heatmap. The Heatmap looks beautiful. I have 2 question on how to make it better: 1. the number of column5 is a little bit different from column1-4 because it is (column3-column1). It contains negative value. So the color can not exactly match what I set for column 1-4. So, my question is in ComplexHeatmap, is it possible to set the column5 side by side(same gene cluster) to column 1-4 with a different color pannel?
When I run the code from the github, I got an error, which I can not understand why:
for (i in 1:length(row_order(HM))){
since mydat_2 is a matrix, why extract the rows is not a matrix?
I hope I expressed myself clear and thanks for any kind of advice,