如何摆脱从arrangeGrob随机背景网格 [英] how do I get rid of random background grid from 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
这个灰色的东西在右下角从哪里来?我该如何摆脱它?
请注意,我无法通过更改 更新 $ b <包装作者(?)回答如下:我应该使用 类似的问题仍然存在(也许是相同的根本原因?):如果之前绘制了某个对象,则空点仍然会被过去图占据。奇怪的是, 可以产生: 产生 为了摆脱过去的文物图(根据上述更新)使用 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 This works fine, but oddly, Like so: yields a plot with some weird gray stuff in the bottom right corner: Compare this to 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 UPDATE The package author (?) answered below: I should have used 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: yields: yields To get rid of artefacts from past plots (as per above update) use 这篇关于如何摆脱从arrangeGrob随机背景网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! ncol
来避免空白点 code>;我有时候的地块数量不均匀,所以总会出现空白点。
我可以空着点,我只是喜欢他们干净。
(单独来说,最后一句听起来很漂亮 OCD-ish < a>。
grid.draw(y)
。
像这样:
plot(p1)
grid.draw(y)
arrangeGrob()
现在返回一个gtable,您应该使用 grid.draw()
绘制,而不是绘图()
。
grid.draw(y)
grid.newpage()
。arrangeGrob()
-- not grid.arrange()
-- because I want to save the plot for later, not plot()
it right away.arrangeGrob()
leaves some weird background in the empty spots.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)
grid.arrange()
:grid.arrange(p1, p2, p3, ncol = 2)
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.
grid.draw(y)
.plot(p1)
grid.draw(y)
arrangeGrob()
now returns a gtable, which you should draw with grid.draw()
, not plot()
.grid.draw(y)
grid.newpage()
.