I just updated R, R Studio, and a bunch of packages including ggplot2 and gridExtras on my Mac. Now gridExtras is failing in basic plotting with the error:
"only 'grobs' allowed in "gList""
Here's some code that should work but does not:
library(ggplot2)
p1 = qplot(1:10,rnorm(10))
p2 = qplot(1:10,rnorm(10))
library(gridExtra)
grid.arrange(p1, p2, ncol=2, main = "Main title")
This dumps out the following error:
Error in gList(list(grobs = list(list(x = 0.5, y = 0.5, width = 1, height = 1, :
only 'grobs' allowed in "gList"
In addition: Warning message:
In grob$wrapvp <- vp : Coercing LHS to a list
Any help is appreciated!
Best Answer
It is because
grid.arrange
does not have amain
parameter anymore (seems to have been eliminated around Summer 2015 with the 2.0.0 release) and thus thinks that themain=
parameter must be a grob. To replace themain
, you can use thetop
parameter now (as well as abottom
,left
, andright
).So this works for example:
The message is a bit confusing, that is because it looks at all the parameters it does not know and assumes they might be
grobs
(graphical objects) that it can plot. A confusing error message like this is the price you pay for that flexibility.Note: - if you have a lot of
grobs
you should consider packing them all into a list and use the form:Here is what that above code results in: