1

I have 3 heatmap plots generated using CRAN package heatmap. I want to put these three images in one slide then I used the following command

cowplot::plot_grid(mfs, mfs_ma, mfs_fe,ncol= 3, labels=LETTERS[1:3])

but it return me

Warning messages: In as_grob.default(plot) :Cannot convert object of class pheatmap into a grob

Therefore,how I can put these three images in one slide.

5
  • For cowplot::plot_grid, input must be ggplot object. Commented Jun 26, 2020 at 9:14
  • Or use par(mfrow = c(1, 3)), then plot 3 plots. Commented Jun 26, 2020 at 9:15
  • well, I did that already but didn't put them in one slide. It just plots each one by one Commented Jun 26, 2020 at 9:35
  • Can you provide link to the package, and your code to create mfs, mfs_ma, mfs_fe objects Commented Jun 26, 2020 at 10:03
  • Related post www.greatytc.com/a/31768236/680068 Commented Jun 26, 2020 at 10:06

1 Answer 1

4

Your heatmaps mfs, mfs_ma, mfs_fe are pheatmap objects.
Consider the following simple example:

library(pheatmap)
test <- matrix(rnorm(200), 20, 10)
mfs <- mfs_ma <- mfs_fe <- pheatmap(test)

You can arrange the 3 heatmaps into a single plot using:

cowplot::plot_grid(mfs$gtable, mfs_ma$gtable, mfs_fe$gtable,
                   ncol= 3, labels=LETTERS[1:3])

or

gridExtra::grid.arrange(grobs=list(mfs$gtable, mfs_ma$gtable, mfs_fe$gtable), 
                        ncol= 3, labels=LETTERS[1:3])

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

will this work for complexheatmap objects? where my row dimension are different ,and I want them just like the solution you had given
@PesKchan Interesting question...! Please, post your question on stackoverflow (with a good, simple, reproducible example).
I figured out gb<-grid.grabExpr(draw(H1_high)) this converts the complexheatmap object which can be used for gridplot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.