saving a base r plot as an object that can be plotted in a multiplot

半世苍凉 提交于 2019-12-06 15:33:24
B. Davis

As correctly noted by @MrFlick, the accepted answer linked here is a better approach than the %<a-% function which does not store a grid.

The code below produces the desired result.

library(ggplot2)
library(gridExtra)
library(gridGraphics)
library(grid)

Fig1 <- qplot(speed, data=cars, geom="histogram")
Fig2 <- qplot(dist, speed, data=cars, geom="point")

plot(cars$speed, cars$dist)
grid.echo()
Fig3 <- grid.grab()

Figs <- grid.arrange(Fig1, Fig2, Fig3,
                     layout_matrix = rbind(c(1,1,1,2,2), c(1,1,1,2,2), c(3,3,3,3,3)))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!