如何摆脱从arrangeGrob随机背景网格 [英] how do I get rid of random background grid from arrangeGrob

查看:157
本文介绍了如何摆脱从arrangeGrob随机背景网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在网格中包裹多个图块,通常是不平衡的数量,所以通常会有一个空白点。
我需要使用 arrangeGrob() - 不是 grid.arrange() - 因为我想要以后保存这个图,而不是 plot()就可以了。



这很好,但奇怪的是, arrangeGrob()在空白处留下一些奇怪的背景。



像这样:$ b $ (ggplot2)
p1 < - ggplot(mtcars,aes(x = factor(cyl),y = mpg))+ geom_boxplot( )
p2 < - ggplot(mtcars,aes(x = factor(cyl),y = wt))+ geom_boxplot()
p3 < - ggplot ),y = disp))+ geom_boxplot()
library(gridExtra)
y< - arrangeGrob(p1,p2,p3,ncol = 2)
plot(y)

会在右下角显示一些奇怪的灰色内容:



grid.arrange()

  grid.arrange(p1,p2 ,p3,ncol = 2)

产生一个没有灰色怪异的漂亮情节: b
$ b



这个灰色的东西在右下角从哪里来?我该如何摆脱它?



请注意,我无法通过更改 ncol 来避免空白点 code>;我有时候的地块数量不均匀,所以总会出现空白点。
我可以空着点,我只是喜欢他们干净。
(单独来说,最后一句听起来很漂亮 OCD-ish < a>。





更新 $ b <包装作者(?)回答如下:我应该使用 grid.draw(y)



类似的问题仍然存在(也许是相同的根本原因?):如果之前绘制了某个对象,则空点仍然会被过去图占据。奇怪的是,
像这样:

  plot(p1)
grid.draw(y)

可以产生:

解决方案

arrangeGrob()现在返回一个gtable,您应该使用 grid.draw()绘制,而不是绘图()

  grid.draw(y)

产生





为了摆脱过去的文物图(根据上述更新)使用 grid.newpage()


I need to wrap several plots in a grid, often an uneven number, so there'll often be an "empty spot". I need to use arrangeGrob() -- not grid.arrange() -- because I want to save the plot for later, not plot() it right away.

This works fine, but oddly, arrangeGrob() leaves some weird background in the empty spots.

Like so:

library(ggplot2)
p1 <- ggplot(mtcars, aes(x=factor(cyl), y=mpg)) + geom_boxplot()
p2 <- ggplot(mtcars, aes(x=factor(cyl), y=wt)) + geom_boxplot()
p3 <- ggplot(mtcars, aes(x =factor(cyl), y=disp)) + geom_boxplot()
library(gridExtra)
y <- arrangeGrob(p1, p2, p3, ncol = 2)
plot(y)

yields a plot with some weird gray stuff in the bottom right corner:

Compare this to grid.arrange():

grid.arrange(p1, p2, p3, ncol = 2)

yields a pretty plot with no grey weirdness:

Where does this gray stuff in the bottom right corner come from? And how do I get rid of it?

Notice that I cannot avoid the empty spots by changing ncol; I sometimes have an uneven number of plots, so there'll always be empty spots. I'm ok with empty spots, I just like them to be clean. (In isolation, that last sentence sounds pretty OCD-ish.


UPDATE

The package author (?) answered below: I should have used grid.draw(y).

A similar problem remains (maybe the same root cause?): if you plot some object before, the "empty spot" remains occupied by that past plot. Weird. Like so:

plot(p1)
grid.draw(y)

yields:

解决方案

arrangeGrob() now returns a gtable, which you should draw with grid.draw(), not plot().

grid.draw(y)

yields

To get rid of artefacts from past plots (as per above update) use grid.newpage().

这篇关于如何摆脱从arrangeGrob随机背景网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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