<p>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.</p>
<p>In case you don't want to run hclust outside of the CH, you can use <code>row_order</code> and <code>column_order</code> to re-order your data in the CH display order.</p>
<pre><code>library(ComplexHeatmap)

ht = Heatmap(heat1)
r_o &lt;- row_order(ht)
c_o &lt;- column_order(ht)
heat1_reordered &lt;- heat1[r_o, c_o]
heat1_reordered[1:35,1:5]
</code></pre>
<p>CH does say that clustering is oly &quot;fixed&quot; on <code>draw</code>ing, so you may want to run this before picking the row and column orders:</p>
<pre><code>pdf(NULL)
ht &lt;- draw(ht)
dev.off()
</code></pre>

CC BY-SA 4.0
2022-03-01T15:05:09.247Z
2022-03-01T15:05:09.247Z
Ram RS
<p>I have a heatmap</p>
<p>I see a block of genes for a group of samples</p>
<p>How I can select a part of heatmap?</p>
<p>I mean is there any way to export a list of genes from rows of a heatmap in R?<a href="https://i.sstatic.net/yTNPp.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/yTNPp.png" alt="enter image description here" /></a></p>
<p>I have tried which returns nothing</p>
<pre><code>&gt; library(ComplexHeatmap)

&gt; ht = Heatmap(heat1) 
&gt; ht[1:35,1:5]
</code></pre>

CC BY-SA 4.0
2022-03-01T12:26:25.447Z
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?
llrs
CC BY-SA 4.0
2022-03-01T12:28:55.167Z
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?
Zizogolu
CC BY-SA 4.0
2022-03-01T13:52:01.877Z
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.
llrs
CC BY-SA 4.0
2022-03-01T15:05:52.947Z
You should really read the manual before asking questions here.
Ram RS
<r><heatmap>
Selecting a part of heatmap
# Selecting a part of heatmap

(Asked by: username_0 on 2022-03-01)

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?
I have tried which returns nothing
> library(ComplexHeatmap)

> ht = Heatmap(heat1) 
> ht[1:35,1:5]

**Tags:** r, heatmap
> **Comments:**
> **username_1**: 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?  
> **username_0**: 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?  
> **username_1**: 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.  
> **username_2**: You should really read the manual before asking questions here.  

---

## 1 answers

### Answer by username_2 on 2022-03-01. Score: 3

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.
library(ComplexHeatmap)

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

CH does say that clustering is oly "fixed" on drawing, so you may want to run this before picking the row and column orders:
pdf(NULL)
ht <- draw(ht)
dev.off()


---

