<p>Please read through the <a href="https://jokergoo.github.io/ComplexHeatmap-reference/book/" rel="nofollow noreferrer">ComplexHeatmap manual</a>, especially the section on row and column orders: <a href="https://jokergoo.github.io/ComplexHeatmap-reference/book/a-single-heatmap.html#get-orders-and-dendrograms-from-heatmap" rel="nofollow noreferrer">https://jokergoo.github.io/ComplexHeatmap-reference/book/a-single-heatmap.html#get-orders-and-dendrograms-from-heatmap</a></p>

<p>You can use <code>row_order</code> and <code>column_order</code> following a <code>draw()</code> (which you can nest between a <code>pdf(null)</code> and <code>dev.off()</code> to disable drawing it on any device). That way, you'll be sure to get the right order from the first heatmap to use with the second.</p>

<p>By nesting, I mean like so:</p>

<pre><code>h1 &lt;- Heatmap(...)
pdf(NULL)
h1d &lt;- draw(h1)
dev.off()
ro1 &lt;- row_order(h1d)
co1 &lt;- column_order(h1d)
</code></pre>

<p>Use whichever (row/column) order is appropriate to gene order.</p>

CC BY-SA 4.0
2020-02-29T02:04:28.177Z
2020-02-29T02:04:28.177Z
Ram RS
<p>I have 2 dataframe with same genes both different data sets</p>

<p>like </p>

<pre><code>&gt; head(heat1[1:3,1:4])
             A10         A11        A12        A2
ATP5F1 2.1163092  0.32044094 -0.5661269 0.7978236
DDX5   0.6277182 -1.67055853 -0.0123082 0.8895472
EEF1G  1.6459212  0.02923401 -1.2737676 0.5842162
&gt; 

&gt; head(heat2[1:3,1:4])
              A10        A12          A3          A4
A2M    -0.6031969  0.6378864 0.000573381 -0.07769313
ABCB11  0.5600164  0.3087120 0.171636836  1.25681512
ABCC2   0.2093133 -0.5608016 0.782278709  0.16618683
&gt;
</code></pre>

<p>I want to plot them side by side with the same order of genes </p>

<p>I tried</p>

<pre><code>&gt; ht1 = Heatmap(heat1)
&gt; ht2 = Heatmap(heat2)
&gt; ht_list = ht1 + ht2
&gt; draw(ht_list, ht_gap = unit(1, "cm"))
Warning message:
Row names of heatmap 2 is not consistent as the main
heatmap (1) 
</code></pre>

<p>But I getting not the same order of genes</p>

<p><a href="https://i.sstatic.net/4Lojp.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4Lojp.png" alt="enter image description here"></a></p>

<p>Can you help me with this?</p>

<r><complexheatmap>
Drawing 2 heatmaps with the same gene order
# Drawing 2 heatmaps with the same gene order

(Asked by: username_0 on 2020-02-28)

I have 2 dataframe with same genes both different data sets
like 
> head(heat1[1:3,1:4])
             A10         A11        A12        A2
ATP5F1 2.1163092  0.32044094 -0.5661269 0.7978236
DDX5   0.6277182 -1.67055853 -0.0123082 0.8895472
EEF1G  1.6459212  0.02923401 -1.2737676 0.5842162
> 

> head(heat2[1:3,1:4])
              A10        A12          A3          A4
A2M    -0.6031969  0.6378864 0.000573381 -0.07769313
ABCB11  0.5600164  0.3087120 0.171636836  1.25681512
ABCC2   0.2093133 -0.5608016 0.782278709  0.16618683
>

I want to plot them side by side with the same order of genes 
I tried
> ht1 = Heatmap(heat1)
> ht2 = Heatmap(heat2)
> ht_list = ht1 + ht2
> draw(ht_list, ht_gap = unit(1, "cm"))
Warning message:
Row names of heatmap 2 is not consistent as the main
heatmap (1) 

But I getting not the same order of genes

Can you help me with this?

**Tags:** r, complexheatmap

---

## 1 answers

### Answer by username_1 on 2020-02-29. Score: 3

Please read through the ComplexHeatmap manual, especially the section on row and column orders: https://jokergoo.github.io/ComplexHeatmap-reference/book/a-single-heatmap.html#get-orders-and-dendrograms-from-heatmap
You can use row_order and column_order following a draw() (which you can nest between a pdf(null) and dev.off() to disable drawing it on any device). That way, you'll be sure to get the right order from the first heatmap to use with the second.
By nesting, I mean like so:
h1 <- Heatmap(...)
pdf(NULL)
h1d <- draw(h1)
dev.off()
ro1 <- row_order(h1d)
co1 <- column_order(h1d)

Use whichever (row/column) order is appropriate to gene order.


---

