0

I am trying to find a way to fit multiple plots in a customized fashion in three rows on a PDF. For the first row I want to plot a hierarchal clustering dendrogram, then for the second row I want two tables side by side generated using the tableGrob function of the extraGrid library. For the third row I want to fit a heatmap. Appreciate all your inputs and suggestions.

This is the snippet of my code:

pdf("test.pdf", width = 12, height = 10)
layout(matrix(c(1,2,4,1,3,4),3,2))
plot(hierarchal,label=Duration,main=label)
grid.arrange(x) #table1
grid.arrange(y) #table2
ggplot(data_heat, aes(x=time, y=gene)
dev.off()
Mdhale
  • 815
  • 2
  • 15
  • 22
  • 2
    It is sort of unclear what data is going into this or how much progress you have. I was going to maybe recommend the cowplot package though as it works great with multiple ggplots – Colin D Apr 27 '17 at 00:10
  • 1
    If I understand your question correctly, you need to look at the `layout` function. Try `layout(matrix(c(1,2,4,1,3,4),3,2))`. – Lamia Apr 27 '17 at 00:15
  • Colin, the above is just the last part of the code. Most variables hierarchal, x , y and data_heat is already processed/generated way up in the code. – Mdhale Apr 27 '17 at 00:16
  • Lamia, thank you for your response. With what you gave me the first row(dendrogram) is generated perfectly. (plot(hierarchal,label=Duration,main=label,col=1) How do I fit x and y side by side? – Mdhale Apr 27 '17 at 00:20
  • You would add the call to layout() after your call to pdf(), so in line 2, and then you just call your 4 plots, before calling dev.off(). They should all fit as you want. – Lamia Apr 27 '17 at 00:23
  • Lamia, I have updated the code to reflect your suggestion. All my plots are generated as a separate frames(each on different page, including x and y). Am I doing something wrong? – Mdhale Apr 27 '17 at 00:32
  • Well `layout` is a base function to define the layout of your plotting device. But you're right it's not working with the functions you use. Within the `gridExtra` package, there seem to be options to define the layout. Have a look at this question: [link] (https://stackoverflow.com/questions/17059099/saving-grid-arrange-plot-to-file) – Lamia Apr 27 '17 at 00:59

0 Answers0