在ggplot2中创建任意窗格 [英] Creating arbitrary panes in ggplot2
问题描述
在基本图形中,我可以通过执行以下操作来创建4个面板图形:
par(mfrow = c 2,2))
pre>
(i在1:4){
plot(density(rnorm(100)))
}
导致
我想用ggplot2做同样的事情,但我无法弄清楚怎么做。我不能使用方面,因为我的真实数据与这个微不足道的例子不同,它的结构非常不同,我希望两个图形是点图,两个是直方图。如何在ggplot2中创建面板或窗格?
解决方案以下是Josh O'Brien的例子:我很惊讶没有人提到过
grid.arrange
来自gridExtra
软件包
<$ p $ b $library(gridExtra)
pre>
grid.arrange(q1,q2,q3,q4,q5,q6,nrow = 3)
这里似乎提到:在一个画布中使用ggplot2绘制多个图
对于我来说,它比记住所有视口的东西容易得多。 $ b
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))) }
which results in
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?
解决方案Following Josh O'Brien's example: I'm surprised no one has mentioned
grid.arrange
from thegridExtra
package yet:library(gridExtra) grid.arrange(q1,q2,q3,q4,q5,q6,nrow=3)
This seems to be mentioned here: multiple graphs in one canvas using ggplot2
For me, it's much easier than remembering all the viewport stuff.
这篇关于在ggplot2中创建任意窗格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!