无法将textGrob作为主要传递给do.call(" arrangeGrob")

时间:2015-07-11 22:59:49

标签: r ggplot2 gridextra grob

虽然

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

工作正常,

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!"

我需要main作为textGrob才能设置字体大小和字体。任何人都知道我做错了什么?

2 个答案:

答案 0 :(得分:2)

问题来自于do.call的参数列表不正确,

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

&#34;曝光&#34; 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版本(&gt; = 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"))

答案 1 :(得分:0)

经过数小时的谷歌搜索后,我在发布问题后直接找到答案.....

以下作品:

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