R - How to print more than three tables on one page in a PDF file

I am trying to create a multi-page PDF from R containing both data.frames and ggplots. I managed to do this by converting data.frames to grobs and using grid.arrange function.

Now the problem is that I want to print five tables / rodents on the first page in PDF, one below the other. On page 2, I only want one table as it contains different data types. Page 3 will contain ggplot. It works great to fit up to three tables on one page, but as soon as I try with four or more it will print them in two columns and they overlap.

Here's what I've tried so far:

# Load required packages
library(gridBase)
library(gridExtra)
library(ggplot2)

# Transform tables into grobs
Table1 <- tableGrob(df1)
Table2 <- tableGrob(df2)
Table3 <- tableGrob(df3)
Table4 <- tableGrob(df4)
Table5 <- tableGrob(df5)
Table6 <- tableGrob(df6)

# Create the PDF file

pdf("file.pdf", height = 15, width = 20)
layout(matrix(c(1,2,3,4,5,6), 1, 6, byrow = TRUE))
grid.arrange(Table1, Table2, Table3, Table4, Table5)
grid.arrange(Table6)
grid.arrange(ggplot1)
dev.off()

      

Does anyone know where I am going wrong?

Many thanks!

Cheers, Tillman

This is what the first PDF page looks like once I use more than three tables. I want them to be in the same column

+3


source to share


2 answers


Just solved it - and of course there is a simple solution that I hadn't thought of.

grid.arrange(Table1, Table2, Table3, Table4, Table5, ncol = 1, nrow = 5)

      



Just adding ncol and nrow makes the deal.

+2


source


Try using or looking for feature options \newpage

? This goes beyond the piece.



0


source







All Articles