ggplot2 在 grid.arrange 中添加两个图,在 R 中的第二个图中插入一个

ggplot2 add two plots in grid.arrange with an inset in the second one in R

我能够打印插图并根据 ggplots 中的绘图创建网格。但是我无法创建一个网格,左边有一个图,右边有 2 个图,一个是全尺寸,另一个是 "inset"。

a_plot <- ggplot(cars, aes(speed, dist)) + geom_line()

#The inset 
print(a_plot);print(a_plot, vp = vp)

# the Grid
lay <- rbind(c(1,1,1,2,2,2),
             c(1,1,1,2,2,2),
             c(1,1,1,2,2,2),
             c(1,1,1,2,2,2))
grid.arrange(a_plot, a_plot,layout_matrix = lay)

但我想要这个:

我该怎么做?

这行不通

grid.arrange(a_plot, a_plot,print(a_plot, vp = vp),layout_matrix = lay)

我试了,也没用。

a_plot <- ggplot(cars, aes(speed, dist)) + geom_line()
b_plot <- a_plot + annotation_custom(grob = rectGrob(), 
                      xmin = 15, xmax = Inf, ymin=-Inf, ymax=25)


grid.arrange(a_plot, b_plot, ncol=2)