R 报告在1页上写入绘图和表格

R 报告在1页上写入绘图和表格,r,ggplot2,gridextra,R,Ggplot2,Gridextra,我希望使用R生成一份1页的报告,如下所示: 左上角: 图1图2 地块3地块4 右上角: 地块5(地块1:4的4倍大) 右下角: 桌子 然后,此页面将重新运行约100次,以便报告的每一页都是相同的,但在本例中,每一页仅用于不同的存储 我希望使用ggplot为5个绘图执行此操作。我可以分别制作所有6个项目,但我真的不知道如何将它们整齐地放在上面布局的1页上 我读了一些关于乳胶的文章,但不确定我是不是在浪费时间。我喜欢基本的layout()和par(mfrow)功能,但我不知道该怎么做,因为我需要gg

我希望使用R生成一份1页的报告,如下所示:

左上角:
图1图2
地块3地块4

右上角: 地块5(地块1:4的4倍大)

右下角: 桌子

然后,此页面将重新运行约100次,以便报告的每一页都是相同的,但在本例中,每一页仅用于不同的存储

我希望使用
ggplot
为5个绘图执行此操作。我可以分别制作所有6个项目,但我真的不知道如何将它们整齐地放在上面布局的1页上

我读了一些关于乳胶的文章,但不确定我是不是在浪费时间。我喜欢基本的
layout()
par(mfrow)
功能,但我不知道该怎么做,因为我需要
ggplot2
绘图的类似功能

因此,左上角的4个绘图可以使用以下方法完成:

library(gridExtra)
grid.arrange(plot1,plot2,plot3,plot4,ncol=2,nrow=2)
grid.table(head(iris))
我真正需要的是

grid.arrange(plot1,plot2,(no plot),(no plot),plot3,plot4,(no plot),(no plot), 
                                                                 ncol=4,nrow=3)
类似这样的操作将在右上角为plot 5准备绘图区域,并在底部为表格留出空间

所以我的问题是

  • 如何使用ggplot2绘图将绘图1:4(大小相同)和绘图5(大小为绘图1:4的4倍)全部按计划显示在页面上
  • 我怎样才能在右下角找到一张桌子
  • 我喜欢这张桌子的外观:
    grid.table
    函数来自
    gridExtra

    我需要的表是6行*5列。比如:

    library(gridExtra)
    grid.arrange(plot1,plot2,plot3,plot4,ncol=2,nrow=2)
    
    grid.table(head(iris))
    
    唯一的问题是它总是被扔到中间,我不知道如何控制它,使它位于右下角


    有什么建议吗?

    我认为您可以使用嵌套的
    排列grob
    创建您想要的内容。让我举例说明:

    library(ggplot2)
    library(gridExtra)
    
    # create a dummy ggplot and its gtable
    g <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
    gt <- ggplot_gtable(ggplot_build(g))
    gt$layout$clip[gt$layout$name=="panel"] <- "off"
    
    # create a table grob
    my_table <- tableGrob(head(mtcars))
    
    # arrange the 5 plots and the table
    grid.arrange(arrangeGrob(
                 arrangeGrob(gt, gt, gt, gt, ncol=2), ## 4 top left panels
                             gt, ncol=2),             ## 1 top right panel
                             my_table, nrow=2)  ## bottom table
    
    库(ggplot2)
    图书馆(gridExtra)
    #创建虚拟ggplot及其gtable
    
    g我认为您可以使用嵌套的
    arrangeGrob
    创建您想要的内容。让我举例说明:

    library(ggplot2)
    library(gridExtra)
    
    # create a dummy ggplot and its gtable
    g <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
    gt <- ggplot_gtable(ggplot_build(g))
    gt$layout$clip[gt$layout$name=="panel"] <- "off"
    
    # create a table grob
    my_table <- tableGrob(head(mtcars))
    
    # arrange the 5 plots and the table
    grid.arrange(arrangeGrob(
                 arrangeGrob(gt, gt, gt, gt, ncol=2), ## 4 top left panels
                             gt, ncol=2),             ## 1 top right panel
                             my_table, nrow=2)  ## bottom table
    
    库(ggplot2)
    图书馆(gridExtra)
    #创建虚拟ggplot及其gtable
    
    g我认为您可以使用嵌套的
    arrangeGrob
    创建您想要的内容。让我举例说明:

    library(ggplot2)
    library(gridExtra)
    
    # create a dummy ggplot and its gtable
    g <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
    gt <- ggplot_gtable(ggplot_build(g))
    gt$layout$clip[gt$layout$name=="panel"] <- "off"
    
    # create a table grob
    my_table <- tableGrob(head(mtcars))
    
    # arrange the 5 plots and the table
    grid.arrange(arrangeGrob(
                 arrangeGrob(gt, gt, gt, gt, ncol=2), ## 4 top left panels
                             gt, ncol=2),             ## 1 top right panel
                             my_table, nrow=2)  ## bottom table
    
    库(ggplot2)
    图书馆(gridExtra)
    #创建虚拟ggplot及其gtable
    
    g我认为您可以使用嵌套的
    arrangeGrob
    创建您想要的内容。让我举例说明:

    library(ggplot2)
    library(gridExtra)
    
    # create a dummy ggplot and its gtable
    g <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
    gt <- ggplot_gtable(ggplot_build(g))
    gt$layout$clip[gt$layout$name=="panel"] <- "off"
    
    # create a table grob
    my_table <- tableGrob(head(mtcars))
    
    # arrange the 5 plots and the table
    grid.arrange(arrangeGrob(
                 arrangeGrob(gt, gt, gt, gt, ncol=2), ## 4 top left panels
                             gt, ncol=2),             ## 1 top right panel
                             my_table, nrow=2)  ## bottom table
    
    库(ggplot2)
    图书馆(gridExtra)
    #创建虚拟ggplot及其gtable
    g 1)有一个
    布局
    参数,该参数模拟基地中的布局。2) 什么样的表?1)有一个
    layout
    参数,它模仿了base中的布局。2) 什么样的表?1)有一个
    layout
    参数,它模仿了base中的布局。2) 什么样的表?1)有一个
    layout
    参数,它模仿了base中的布局。2) 什么样的桌子?