2015-07-11 43 views
0

虽然无法通过textGrob为主,以do.call( “arrangeGrob”)

作品就好了,

test <- do.call("arrangeGrob", c(plots.list[1:2],ncol=2,main=textGrob("test"))) 

提供了以下错误:

"Error in arrangeGrob(list(grobs = list(list(x = 0.5, y = 0.5, width = 1, : input must be grobs!"

我需要主要是textGrob为了设置字体大小和字体。任何人有一个想法,我在做什么错了?

回答

2

的问题来自于一个事实,即参数列表对于do.call是不正确的,

c(list(1, 2), ncol=1, textGrob("a")) 

“暴露” textGrob的内容,而你真的要追加两个列表,

c(list(1, 2), list(ncol=1, textGrob("a"))) 

适用于你的问题,这成为

do.call("grid.arrange", c(plots.list[1:2],list(ncol=2, main=textGrob("test")))) 

但要注意gridExtra的即将发布的版本(> = 2.0.0)不再承认main,你应该使用top代替

do.call("grid.arrange", c(plots.list[1:2],list(ncol=2, top=textGrob("test")))) 

并且,由于arrangeGrob获得了新的grobs论点,因此您不需要do.call了,

grid.arrange(grobs=plots.list[1:2], ncol=2, top=textGrob("test")) 
+0

我试过'arrangeGrob(grobs = plots.list [1:4],ncol = 2)'但stil得到错误'输入必须是grobs!'。 'arrangeGrob(plots.list [[1]],plots.list [[2]],plots.list [[3]],plots.list [[4]],ncol = 2)'的作品。 do.call提示工作虽然!非常非常感谢你! –

0

之后谷歌搜索的时间,我找到了答案已经直接贴出问题后.....

以下工作:

test <- do.call("grid.arrange",c(plots.list, ncol=2, main =substitute(textGrob("test"),env = parent.frame())))