Error with grid.arrange: input must be grobs

I have the following R-Script:

library(ggplot2) library(gridExtra) Sys.setenv(LANG ="en") c1 <- ggplot(mtcars, aes(factor(cyl))) + geom_bar() c2 <- ggplot(mtcars, aes(factor(cyl))) + geom_bar() + coord_flip() grid.arrange(c1, c2, ncols=1) 

I get the following error with grid.arrange:

Organization Error Grob (..., as.table = as.table, clip = clip, main = main ,: the input must be grobs!

I can not understand what is causing the problem.

Here are my used versions:

sessionInfo () R version 3.0.2 (2013-09-25) Platform: x86_64-apple-darwin10.8.0 (64-bit)

  locale: [1] de_DE.UTF-8/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] gridExtra_0.9.1 ggplot2_0.9.3.1 loaded via a namespace (and not attached): [1] colorspace_1.2-4 digest_0.6.4 gtable_0.1.2 labeling_0.2 MASS_7.3-31 munsell_0.4.2 plyr_1.8.1 proto_0.3-10 Rcpp_0.11.1 reshape2_1.2.2 [11] scales_0.2.4 stringr_0.6.2 tools_3.0.2 
+7
r ggplot2
source share
1 answer

I liked this mistake, it is secretive. In short, the parameter is ncol , not ncols . In your code, 1 considered as a plot object, so why does it fail, and not because ggplots are invalid. The error message is not very useful, which hides the situation.

 # same error as with ncols=1 grid.arrange(c1, c2, blah=1) # fine grid.arrange(c1, c2, ncol=1) 
+16
source share

All Articles