在ggplot2中创建任意窗格 [英] Creating arbitrary panes in ggplot2

查看:101
本文介绍了在ggplot2中创建任意窗格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基本图形中,我可以通过执行以下操作来创建4个面板图形:

  par(mfrow = c 2,2))
(i在1:4){
plot(density(rnorm(100)))
}
pre>

导致


我想用ggplot2做同样的事情,但我无法弄清楚怎么做。我不能使用方面,因为我的真实数据与这个微不足道的例子不同,它的结构非常不同,我希望两个图形是点图,两个是直方图。如何在ggplot2中创建面板或窗格?

解决方案

以下是Josh O'Brien的例子:我很惊讶没有人提到过 grid.arrange 来自 gridExtra 软件包



<$ p $ b $ library(gridExtra)
grid.arrange(q1,q2,q3,q4,q5,q6,nrow = 3)
pre>

这里似乎提到:在一个画布中使用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 the gridExtra 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屋!

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