grid.arrange错误:输入必须是grobs [英] Error with grid.arrange:input must be grobs

查看:193
本文介绍了grid.arrange错误:输入必须是grobs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下R-Script:

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)

在grid.arrange中出现以下错误:

I get the following error with grid.arrange:


在arrangeGrob(...,as。 table = as.table,clip = clip,main =
main,:input必须是grobs!

Error in arrangeGrob(..., as.table = as.table, clip = clip, main = main, : input must be grobs!

找出导致问题的原因。

以下是我使用的版本:

Here are my used versions:


sessionInfo()
R版本3.0.2(2013-09-25)
平台:x86_64-apple-darwin10.8.0(64位)

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             


推荐答案

我喜欢这个特别的错误,这是一个隐身的问题。长话短说,参数是 ncol ,而不是 ncols 。在你的代码中, 1 被视为一个plot对象,所以这就是它失败的原因,不是因为ggplots无效。该错误消息不是非常有用,这掩盖了情况。

I liked this particular error, this is a stealthy one. Long story short, the parameter is ncol, not ncols. In your code, 1 is treated as a plot object, so that's why it fails, not because ggplots are invalid. The error message is not very helpful, which obscures the situation.

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

这篇关于grid.arrange错误:输入必须是grobs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆