存储安排到对象,不会创建可打印的对象 [英] store arrangeGrob to object, does not create printable object

查看:102
本文介绍了存储安排到对象,不会创建可打印的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存,但不打印(现在),一堆 ggplot() s到网格中(通过 arrangeGrob(),正确?),然后打印并在稍后检索它们。 这是现有问题
奇怪的是,该答案不起作用,我不知道为什么。
我使用完全相同的代码。

  library(ggplot2)
p1 < - ggplot( mtcars,aes(x = factor(cyl),y = wt))+ geom_boxplot()
library(gridExtra)
y< - arrangeGrob(p1,p2)
class(y)
y

奇怪的是,不是(如上面的答案)产生了图的网格,但是:

 > class(y)
[1]gtablegrobgDesc
> y
TableGrob(2 x 1)排列:2 grobs
z单元格名称grob
1 1(1-1,1-1)排列gtable [layout]
2 2 (2-2,1-1)布置gtable [布局]

这里发生了什么? / p>

解决方案

最近更新了 gridExtra $ c> arrangeGrob 在内部工作,返回什么样的对象(现在是 gtable )。

您需要调用 grid.draw

  grid .draw(y)

plot() code>按照最初的建议;它会添加一个灰色背景,仅用于调试gtables。


I want to save, but not print (for now), a bunch of ggplot()s into a grid (via arrangeGrob(), correct?), then print and retrieve them later.

This is a reboot of an existing question. Strangely, that answer does not work, and I have no idea why. I am using the exact same code.

  library(ggplot2)
  p1 <- ggplot(mtcars, aes(x=factor(cyl), y=mpg)) + geom_boxplot()
  p2 <- ggplot(mtcars, aes(x=factor(cyl), y=wt)) + geom_boxplot()
  library(gridExtra)
  y <- arrangeGrob(p1, p2)
  class(y)
  y

Strangely, that does not (as in the above answer) yield the grid of plots, but:

> class(y)
[1] "gtable" "grob"   "gDesc" 
> y
TableGrob (2 x 1) "arrange": 2 grobs
  z     cells    name           grob
1 1 (1-1,1-1) arrange gtable[layout]
2 2 (2-2,1-1) arrange gtable[layout]

What is going on here?

解决方案

The gridExtra package has been updated recently thereby changing how arrangeGrob works internally and what kind of object it returns (now a gtable).

You need to call grid.draw:

grid.draw(y)

Edit: do not use plot() as initially suggested; it will add a grey background, and is only meant to be used for debugging gtables.

这篇关于存储安排到对象,不会创建可打印的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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