Arrange base plots and grid.tables on the same page

后端 未结 1 1081
情深已故
情深已故 2020-11-27 18:15

I have 2 plots (created using Base graphics) and 2 data frames that I would like to combine onto one sheet in a PDF. I\'m using grid.table to create a tableGrobs from my dat

相关标签:
1条回答
  • 2020-11-27 18:33

    To combine base plots and grid objects the package gridBase is useful.

    A rough worked example base on your layout above

    library(grid)
    library(gridBase)
    library(gridExtra)
    
    
    layout(matrix(c(1,3, 2,3, 4,3), nrow = 3, ncol = 2, byrow = TRUE))
    
    # First base plot
    plot(1:10)
    
    # second base plot 
    frame()
    # Grid regions of current base plot (ie from frame)
    vps <- baseViewports()
    pushViewport(vps$inner, vps$figure, vps$plot)
    # Table grob
    grob <-  tableGrob(iris[1:2,1:2])  
    grid.draw(grob)
    
    popViewport(3)
    
    # third base plot
    plot(1:10)
    
    # fourth
    frame()
    vps <- baseViewports()
    pushViewport(vps$inner, vps$figure, vps$plot)  
    grid.draw(grob)
    popViewport(3)
    

    Which gives

    enter image description here

    0 讨论(0)
提交回复
热议问题