强制一个常规的阴谋对象到一个Grob用于grid.arrange [英] force a regular plot object into a Grob for use in grid.arrange
本文介绍了强制一个常规的阴谋对象到一个Grob用于grid.arrange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
b <- ggplot(cars,aes(x=speed,y=dist))+geom_line()
grid.arrange(
b,
plot(cars),
ncol=1
)
给我(列表(grobs = list(list(x = 0.5,y = 0.5,width = 1,height))中的错误
gives me the following error
= 1,:只在'gList'中允许'grobs'
Error in gList(list(grobs = list(list(x = 0.5, y = 0.5, width = 1, height = 1, : only 'grobs' allowed in "gList"
假设我的第二个图必须从 plot
函数。如何将输出转换为 grob
类型的对象,以便与网格很好地配合.arrange
?
Let's assume my second graph has to come out of the plot
function. How would one convert that output to a grob
-like object so it plays nicely with grid.arrange
?
推荐答案
您可以尝试使用gridGraphics
you can try with gridGraphics
library(gridGraphics)
grab_grob <- function(){
grid.echo()
grid.grab()
}
plot(cars)
g <- grab_grob()
b <- ggplot(cars,aes(x=speed,y=dist))+geom_line()
grid.arrange(
b,g,
ncol=1
)
或者使用gridBase。
or, alternatively, use gridBase.
这篇关于强制一个常规的阴谋对象到一个Grob用于grid.arrange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文