维恩图在多个图中 [英] Venn diagrams in multiple figure

查看:97
本文介绍了维恩图在多个图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以将下面的维恩图作为下面两个直方图之后的第三个图? 我想将两个维恩图放在另一个之上

is there a way to have the following venn diagrams as a 3rd figure after the two histograms below?? I'd like to have the two venn diagram one on top of the other

library(VennDiagram)

plus.venn<-draw.pairwise.venn(368, 1171, 149) #venn diagram 1

minus.venn<-draw.pairwise.venn(349, 1335, 173) #venn diagram 2

par(mfrow=c(1,3))

a<-sample(1:10000,3000)

b<-sample(5000:15000,3000)

hist(a)

hist(b)

推荐答案

扩展MrFlicks和我在上面的评论.

Expand upon MrFlicks and my comments above.

您可以使用gridBase包组合基本图形和网格图形.但是,如果您不受限于使用基本R图形,则可能会发现使用基于网格的图形包来生成所有图并使用gridExtra包将它们组合起来更为容易.

You can combine base and grid graphics using the gridBase package. However, if you are not constrained to use base R graphics you may find it easier to produce all your plots using a grid based graphics package and combine them using the gridExtra package.

您的数据

library(VennDiagram)

plus.venn <- draw.pairwise.venn(368, 1171, 149) #venn diagram 1
minus.venn <-draw.pairwise.venn(349, 1335, 173) #venn diagram 2
a <-sample(1:10000,3000)
b <-sample(5000:15000,3000)

安排基准图和网格图

library(grid)
library(gridBase)

# Layout of plots - 4 plots of equal size
layout(matrix(1:4, 2, byrow = TRUE))

# First & second base plot
hist(a)
hist(b)

# Grid regions of current base plot (ie from frame)
frame()
vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)
grid.draw(plus.venn)
popViewport(3)

# fourth
frame()
vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)  
grid.draw(minus.venn)
popViewport(3)

哪个生产

或使用ggplot2生成直方图,并使用grid.arrange

Or using ggplot2 to produce your histograms and combining using grid.arrange

library(ggplot2)
library(gridExtra)

grid.arrange(qplot(a, geom="histogram") + theme_classic(),
             qplot(b, geom="histogram") + theme_classic(),
             grobTree(plus.venn),
             grobTree(minus.venn),
             ncol=2)

哪个生产

您可以将两种方法的布局更改为所需的样式.

You can change the layout of either method to what you want.

这篇关于维恩图在多个图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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