Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple panel plots with pheatmap

I am trying to do multipanel plots one panel being a heatmap using layout to place plots. I've been drawing heatmaps with pheatmap which provides a very convenient color scheme among other things.

The code for pheatmap is available here.

When I try using pheatmap in this way it always plots on a new page. I imagine this is because of its use of the grid package? Is there a way I can do this with pheatmap?

Example code to produce a heatmap next to a barplot but which doesn't since the heatmap gets plotted on a new page below:

xlay=layout( matrix(c(2,2,1),nrow=1) )
layout.show(xlay)
barplot(rnorm(8),horiz=T)
pheatmap(matrix(rnorm(80),nrow=8))
like image 417
Kaleb Avatar asked Oct 18 '25 21:10

Kaleb


1 Answers

Make your bar plot in ggplot

bar <- ggplot()  

Assign both the barplots and heatmap to a variable

heat <- pheatmap(matrix(rnorm(80),nrow=8))

then use gridExtra package to make panel plot the heatmap is saved as an object and you can plot it again by assessing the 4th item in the object

grid.arrange(bar, heat[[4]], nrow = 1)
like image 152
Jake Saunders Avatar answered Oct 21 '25 12:10

Jake Saunders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!