How to combine multiple pheatmap figures and use common legend?
2
0
Entering edit mode
11 months ago
tianshenbio ▴ 110

I currently have four heatmaps generated by pheatmap(): hp1.hp2.hp3, and hp4. I know that these heat maps can be combined in one canvas using grid.arrange(). But how can I use a common legend for all heatmaps? This can be achieved using ggarrange() when setting common.legend = TRUE.However, since these heatmaps are not ggplot items, ggarrange() cannot be used. What should I do?

R pheatmap ggarrange gridarrange • 1.8k views
ADD COMMENT
0
Entering edit mode

did you try grid package? @ tianshenbio

ADD REPLY
0
Entering edit mode

Hi, I used the grad.arrange() function from gridExtra package. I just tried to mute the legends of each individual figure and added a common one for the whole plot, it worked well. Thank you

ADD REPLY
2
Entering edit mode
11 months ago
lessismore ★ 1.1k

Hi! You can use ggplotify and patchwork . Here a reproducible example. It doesn't collect the legends though..

# load libraries
library(ggplot2)
library(ggplotify)
library(pheatmap)
library(patchwork)

# create random dataframe
df = data.frame(matrix(rnorm(20), nrow=10))

# save plots
p1 <- as.ggplot(pheatmap(df))
p2 <- as.ggplot(pheatmap(df))

# use patchwork to arrange them together
p1 + p2

enter image description here

ADD COMMENT
0
Entering edit mode
11 months ago
YiweiZhu ▴ 30

Maybe the R package ComplexHeatmap produced by Zuguang Gu can help you. https://github.com/jokergoo/ComplexHeatmap

ADD COMMENT

Login before adding your answer.

Traffic: 1245 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6