代码之家  ›  专栏  ›  技术社区  ›  SkyWalker

如何获得基本图形绘图。通过arrangeGrob与他人结合的新手?

  •  2
  • SkyWalker  · 技术社区  · 8 年前

    plot.new() 等:

    p1 <- generate_ggplot1(...)
    p2 <- generate_ggplot2(...)
    p3 <- generate_ggplot3(...)
    
    # how to get hold of the plot output and make it available as 
    # p4 for arrangeGrob?
    plot.new()
    ...
    
    final <- gridExtra::arrangeGrob(p1, p2, p3, p4, layout_matrix = rbind(c(1,2), c(3,4)), widths=c(7,7), heights=c(7,7))
    ggplot2::ggsave(filename=output.file,plot=final,width=14,height=14)
    

    ggplot2

    1 回复  |  直到 7 年前
        1
  •  5
  •   baptiste    8 年前

    尝试 this ,

    library(gridGraphics)
    library(grid)
    library(gridExtra)
    library(ggplot2)
    
    grab_grob <- function(...){
      grid.echo(...)
      grid.grab()
    }
    
    b <- grab_grob(function() plot(cars))
    g <- ggplot()
    
    grid.arrange(b, g)