Question: Using the row order of one pheatmap to set the order of another. How to do it?
gravatar for achamess
3.3 years ago by
United States
achamess50 wrote:

Hi. I'm using pheatmap to create heatmaps. I've made a heatmap and used the clustering option (method = correlation) and the resulting heatmap has a certain row order based on the clustering. I want to make another heatmap using pheatmap that then has the same row order as the first one. Is there a way to specifically set the order of a second pheatmap based on the first?

I've been trying using the tree_row$order argument on the pheatmap object that I create. I think I can use this to set the order of the other, but then I don't know how to get pheatmap to display/write to file the changed pheatmap object.

Here's an example of some code:

create a pheatmap

hm_1<-pheatmap(mat1, cluster_rows=TRUE) hm_2<-pheatmap(mat1, cluster_rows=FALSE)

get the row order of another pheatmap and set the first to the second

hm_2$tree_row$order <-hm_1$tree_row$order

This works, but then I have this hm_2 object. How do I get it to display the resulting map again without calling the pheatmap argument?

And is there a batter way to do this?

rna-seq pheatmap R • 4.3k views
ADD COMMENTlink modified 6 months ago by RamRS25k • written 3.3 years ago by achamess50
gravatar for Stephane Plaisance
2.1 years ago by
Leuven area (Belgium)
Stephane Plaisance410 wrote:

you can reorder your second data based on the order of the first heatmap (where clustering has been applied) in my case this was useful to display non-transformed values while plotting the heatmap based on transformed values

1) create the hm pheatmap using transformed and normalized data 2) extract row and col orders from it as you suggested

# capture order for rows from first hm row.order = ph$tree_row$order col.order = ph$tree_col$order

3) reorder the non-transformed data based on the order of the data in the heatmap extracted above = raw[row.order, col.order]

4) plot new pheatmap using the same data but overlay numbers from the raw matrix instead of the transf+norm numbers ..., ...

Hope this helps and can be recycled!

ADD COMMENTlink written 2.1 years ago by Stephane Plaisance410
gravatar for RamRS
6 months ago by
Houston, TX
RamRS25k wrote:

Revisiting this topic so the answer is more current, I highly recommend using ComplexHeatmap. Its manual is comprehensive and covers a ton of options. The developer is active and responsive.

Carrying over row order between heatmaps can be done with

ro_1 <- row_order(heatmap_1)
heatmap_2 <- Heatmap(..., row_order = ro_1, ...)
ADD COMMENTlink written 6 months ago by RamRS25k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1595 users visited in the last hour