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?

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 values.to.show = 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
> ...   display_numbers=values.to.show,    ...

Hope this helps and can be recycled!