2015-07-11 48 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())))