Store output from gridExtra::grid.arrange into an object

后端 未结 2 1312
遥遥无期
遥遥无期 2020-12-20 12:38

I am placing multiple plots into one image using gridExtra::grid.arrange and would like to have the option of saving the combined plot as an object that could b

2条回答
  •  攒了一身酷
    2020-12-20 13:12

    The code in your edit does not work properly since you didn't load gridExtra.

    library(gridExtra)
    y <- arrangeGrob(p1, p2, ncol = 1)
    class(y)
    #[1] "gtable" "grob"   "gDesc"
    grid.draw(y)
    

    enter image description here

    Edit: since version 2.0.0, my comment about grid dependency below is no longer valid, since grid is now imported.

    Edit: With gridExtra version >= 2.0.0, there is no need to attach either package,

    p <- ggplot2::qplot(1,1)
    x <- gridExtra::arrangeGrob(p, p)
    grid::grid.draw(x)
    

提交回复
热议问题