I have a heatmap

I see a block of genes for a group of samples

How I can select a part of heatmap?

I mean is there any way to export a list of genes from rows of a heatmap in R?enter image description here

I have tried which returns nothing

> library(ComplexHeatmap)

> ht = Heatmap(heat1) 
> ht[1:35,1:5]
  • 1
    $\begingroup$ Why would you want to do that? Why not simply subset the data that generates the heatmap to the desired rows? What have you tried to do or searched to do this? $\endgroup$
    – llrs
    Mar 1, 2022 at 12:26
  • $\begingroup$ From a matrix of scaled values, how I can say which miRNAs I want before being clustered and visualized so that in the heatmap I can see a blocked of correlated miRNAs? $\endgroup$
    – Zizogolu
    Mar 1, 2022 at 12:28
  • 1
    $\begingroup$ You can check/create clusters outside the heatmap via hclust. Keep in mind that the heatmap will change if you provided less genes/miRNAs or different samples. But probably can extract the data from ht object. $\endgroup$
    – llrs
    Mar 1, 2022 at 13:52
  • 1
    $\begingroup$ You should really read the manual before asking questions here. $\endgroup$
    – Ram RS
    Mar 1, 2022 at 15:05

1 Answer 1


You're using ComplexHeatmap, which is pretty easy to subset. Your subset operation creates a subset object of the heatmap, not of the data in the heatmap.

In case you don't want to run hclust outside of the CH, you can use row_order and column_order to re-order your data in the CH display order.


ht = Heatmap(heat1)
r_o <- row_order(ht)
c_o <- column_order(ht)
heat1_reordered <- heat1[r_o, c_o]

CH does say that clustering is oly "fixed" on drawing, so you may want to run this before picking the row and column orders:

ht <- draw(ht)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.