Venn diagrams in multiple figure [duplicate]

故事扮演 提交于 2019-12-06 03:03:35

Expand upon MrFlicks and my comments above.

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.

Your data

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)

Arranging base and grid plots

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)

Which produces

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)

Which produces

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!