如何通过 arrangeGrob 获取基础图形 plot.new 与其他图形组合?

How to get hold of the base graphics plot.new to combine with others via arrangeGrob?

我有以下简化的用例。基本上我有一些 ggplot2 图,我想将它们与使用基本图形库 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)

有哪些选择可以做到这一点?与将 p4 重写为原生 ggplot2

分开

尝试,

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)