从gridExtras的grid.arrange退出,“仅在'gList'中允许'grobs'"更新后 [英] grid.arrange from gridExtras exiting with "only 'grobs' allowed in 'gList'" after update

查看:693
本文介绍了从gridExtras的grid.arrange退出,“仅在'gList'中允许'grobs'"更新后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Mac上更新了R,R Studio和一堆软件包,包括ggplot2和gridExtras.现在gridExtras无法进行基本绘图,并显示以下错误:

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:

"gList"中仅允许使用"grobs""

"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")

这将转储以下错误:

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

感谢您的帮助!

推荐答案

这是因为grid.arrange不再具有main参数(似乎在2015年夏季的2.0.0版本中已被淘汰),因此认为main=参数必须是grob.要替换main,您现在可以使用top参数(以及bottomleftright).

It is because grid.arrange does not have a main parameter anymore (seems to have been eliminated around Summer 2015 with the 2.0.0 release) and thus thinks that the main= parameter must be a grob. To replace the main, you can use the top parameter now (as well as a bottom, left, and right).

因此,例如:

library(ggplot2)
p1 = qplot(1:10,rnorm(10))
p2 = qplot(1:10,rnorm(10))

library(gridExtra)
grid.arrange(p1, p2, ncol=2,top="Main Title")

该消息有点令人困惑,这是因为它查看了它不知道的所有参数,并假定它们可能是它可以绘制的grobs(图形对象).像这样令人困惑的错误消息是您为此灵活性付出的代价.

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.

注意:-如果您有很多grobs,则应考虑将它们全部打包到列表中并使用以下格式:

Note: - if you have a lot of grobs you should consider packing them all into a list and use the form:

grid.arrange( grobs = list(p1,p2,...),...

这是上面的代码导致的结果:

Here is what that above code results in:

这篇关于从gridExtras的grid.arrange退出,“仅在'gList'中允许'grobs'"更新后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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