在 ggplot2 中创建任意窗格 [英] Creating arbitrary panes in ggplot2
问题描述
在基本图形中,我可以通过执行以下操作来创建一个 4 面板的图形窗格:
In base graphics I can create a 4 panel pane of graphics by doing the following:
par(mfrow=c(2,2))
for (i in 1:4){
plot(density(rnorm(100)))
}
导致
我想用 ggplot2 做同样的事情,但我不知道该怎么做.我不能使用分面,因为我的真实数据与这个简单的例子不同,它的结构非常不同,我希望两个图是点图,两个图是直方图.如何在 ggplot2 中创建面板或窗格?
I'd like to do the same sort of thing with ggplot2, but I can't figure out how to do it. I can't use facets because my real data, unlike this trivial example, is in very different structures and I want two graphs to be point charts and two to be histograms. How can do create panels or panes in ggplot2?
推荐答案
遵循 Josh O'Brien 的例子:我很惊讶没有人提到 gridExtra
grid.arrange代码>打包:
Following Josh O'Brien's example: I'm surprised no one has mentioned grid.arrange
from the gridExtra
package yet:
library(gridExtra)
grid.arrange(q1,q2,q3,q4,q5,q6,nrow=3)
这里似乎提到了:使用 ggplot2 在一个画布中绘制多个图形
对我来说,这比记住所有视口内容要容易得多.
For me, it's much easier than remembering all the viewport stuff.
这篇关于在 ggplot2 中创建任意窗格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!