绘制嵌套的维恩图 [英] Drawing nested venn diagrams

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

问题描述

我拥有的数据包含用于两组的二进制指示符,以及嵌套在前两组之一中的更多组的数据.

I have data which contain binary indicators for two groups, and to more groups that are nested within one of the first two groups.

例如:

set.seed(1)
df <- data.frame(a=rep(0,10),b=rep(0,10),b.1=rep(0,10),b.2=rep(0,10))
df$a[sample(10,5,replace=F)] <- 1
df$b[sample(10,5,replace=F)] <- 1
df$b.1[sample(which(df$b==1),3,replace=F)] <- 1
df$b.2[sample(which(df$b==1),3,replace=F)] <- 1
df <- df[which(rowSums(df)==0),]

ab是两个组,而b.1b.2嵌套在组b中.

a and b are the two groups and b.1 and b.2 are nested within group b.

我想做的是画一张所有小组的维恩图.这意味着b.1b.2将被限制在b内,这将与a相交.

What I'd like to do is draw one venn diagram of all groups. This means that b.1 and b.2 will be circumscribed within b, which will intersect a.

有什么办法可以做到这一点?使用ggplot解决方案会很棒.

Is there any way to achieve this? Using a ggplot solution would be great.

仅对组b,b.1和b.2尝试R's VennDiagram'不适用于我:

Trying R's VennDiagram' only for groups b, b.1, and b.2 doesn't even work for me:

library(VennDiagram)
draw.triple.venn(area1=sum(df$b),area2=sum(df$b.1),area3=sum(df$b.2),
                   n12=sum(df$b*df$b.1),n23=sum(df$b.1*df$b.2),n13=sum(df$b*df$b.2),n123=sum(df$b*df$b.1*df$b.2),
                   category=c("b","b1","b2"))

使用Vennerable程序包,我仅绘制了"b"组而关闭:

With the Vennerable package I get close only drawing the "b" groups:

library(Vennerable)
plot(Venn(Sets=list(b=which(df$b==1),b.1=which(df$b.1==1),b.2=which(df$b.2==1))),doEuler=T,doWeight=T)

但是当我添加a组时,它会变得混乱:

But when I add the a group it gets messed up:

因为我真正需要的是组a的一个圆,与组b的相交区域,并且在组b的圆内是组b.1b.2的圆.

Because what I really need is one circle for group a with an intersecting area with group b, and within the circle of group b are the circles of groups b.1 and b.2.

推荐答案

主要思想是绘制一个具有ab1b2的三元维恩,然后手动为b覆盖一个椭圆

The main idea is to draw a triple Venn with a, b1, and b2, and then manually overlay an ellipse for b.

library(VennDiagram)
library(gridExtra)
polygons <- draw.triple.venn(
    area1=sum(df$a),
    area2=sum(df$b.1),
    area3=sum(df$b.2),
    n12=sum(df$a*df$b.1),
    n23=sum(df$b.1*df$b.2),
    n13=sum(df$a*df$b.2),
    n123=sum(df$a*df$b.1*df$b.2),
    category=c("a","b1","b2"),
    margin=.1)

现在,我们绘制椭圆并添加标签.这需要经过反复试验才能确定位置,角度和尺寸.就目前而言,它并不完美,但几乎已经存在.

Now we draw the ellipse and add the label. This requires a fair bit of trial and error to get the location, angle, and size right. As it is, it's not perfect, but it's almost there.

b <- ellipseGrob(
    x=unit(0.562,"npc"),
    y=unit(0.515,"npc"),
    angle=(1.996*pi)/3,
    size=65.5, ar=2, gp=gpar(lwd=2.2))
grid.draw(b)
grid.text("b", x=unit(.9,"npc"), y=unit(.9,"npc"), gp=gpar(fontfamily="serif"))

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

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