T. *_*olf 6 r ggplot2 gridextra
我正在尝试从 R 创建一个多页 PDF 文件,其中包含 data.frames 和 ggplots。我设法将 data.frames 转换为 grobs 并使用 grid.arrange 函数。
我现在遇到的问题是我想在 PDF 的第一页上打印五个表格/表格,一个在另一个下面。在第 2 页上,我只想要一张表,因为它包含不同类型的数据。第 3 页将包含一个 ggplot。在一页上放置最多三个表格效果非常好,但是一旦我尝试使用四个或更多表格,它就会将它们打印成两列,并且它们会重叠。
这是我到目前为止尝试过的:
# 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()
Run Code Online (Sandbox Code Playgroud)
有人知道我错在哪里吗?
预先非常感谢!
干杯,蒂尔曼
| 归档时间: |
|
| 查看次数: |
3342 次 |
| 最近记录: |