How to combine multiple pheatmap figures and use common legend?
1
1
Entering edit mode
4.5 years ago
tianshenbio ▴ 180

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 • 10k 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
8
Entering edit mode
4.5 years ago
lessismore ★ 1.4k

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

Thanks, converting pheatmap into a ggplot allows us to use ggarrange neatly.

ADD REPLY

Login before adding your answer.

Traffic: 1650 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