0

While

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

works just fine,

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

gives the following error:

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

I need the main to be a textGrob in order to set font size and font face. Anyone has an idea what I am doing wrong?

Hengrui Jiang
  • 861
  • 1
  • 10
  • 23

2 Answers2

2

The problem comes from the fact that the list of parameters for do.call is not correct,

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

"exposes" the contents of textGrob, while you really want to append two lists,

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

Applied to your question, this becomes

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

but note that the upcoming version of gridExtra (>= 2.0.0) no longer recognises main, you should use top instead

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

and, since arrangeGrob gained a new grobs argument, you don't need do.call anymore,

grid.arrange(grobs=plots.list[1:2], ncol=2, top=textGrob("test"))
baptiste
  • 75,767
  • 19
  • 198
  • 294
  • I tried `arrangeGrob(grobs = plots.list[1:4], ncol = 2)` but stil get the error `input must be grobs!`. `arrangeGrob(plots.list[[1]], plots.list[[2]], plots.list[[3]], plots.list[[4]], ncol=2)` works. The hint for do.call worked though! Thank you very very much! – Hengrui Jiang Jul 14 '15 at 10:46
0

After hours of googling, I found the answer directly after having posted the question.....

The following works:

test <- do.call("grid.arrange",c(plots.list, ncol=2, main =substitute(textGrob("test"),env = parent.frame())))
Hengrui Jiang
  • 861
  • 1
  • 10
  • 23