优化内部标签的Venn图r。

3
我正在尝试以优化的方式绘制一个Venn图(如下所示),并使用案例作为内部标签(而不是每个交集中的案例数)。 我知道有针对它们的每个帖子,但没有一个解决方案可以让我两者兼得。
我有这个:
x <- list()
x$A <- as.character(c("Per_36","Cent","CeM","vDG","LAVL","RSGd"))
x$B <- as.character(c("vCA1","DLE","Per_36","vDG","DIE","Per_35"))
x$C <- as.character(c("vCA1","Cg1","LAVL", "RSGc", "RSGd","Per_35","Per_36"))
x$D <- as.character(c("Por","Cg1","RSGc","LAVL","Per_35","RSGd","Per_36"))


require(VennDiagram)
v0 <-venn.diagram(x, lwd = 3, col = c("red", "green", "orange", "blue"),
                fill = c("red", "blue", "green", "orange"), apha = 0.5, filename = NULL)
grid.draw(v0)
overlaps <- calculate.overlap(x)
overlaps <- rev(overlaps)
for (i in 1:length(overlaps)){
  v0[[i+8]]$label <- paste(overlaps[[i]], collapse = "\n")
}

grid.newpage()
grid.draw(v0)

我得到了以下输出:

enter image description here

关于Venn图的组织,我想要做到这一点:

c <- venn(x, simplify = TRUE, small = 0.5, intersections = TRUE)

enter image description here

我使用gplots()包中的venn函数,并使用simplify = TRUE参数得到了一个图表。然而,在venn函数中,我似乎无法用标签名称替换计数。我使用了intersections = TRUE参数,根据参数说明应该可以实现替换,但它并没有生效(尽管如果我查看变量c的内部信息,信息确实存在)。

    Logical flag indicating if the returned object should have the attribute 
"individuals.in.intersections" featuring for every set a list of individuals
 that are assigned to it.

问题:使用VennDiagram包,是否有一种方法可以像gplots包中的venn函数中的simplify参数一样执行相同的操作?

问题2:使用gplots包中的venn函数,是否有一种方法可以显示每个元素的名称而不是元素计数?就像我在“venn.diagram”函数中所做的那样?

提前致谢,


我正在尝试绘制一个带有内部标签的 Venn 图,你的问题是一个很好的例子,但我只有 3 个列表,所以我无法让它起作用,因为我不知道为什么在这一行代码中你要将索引加 8:v0[[i+8]]$label - Ibo
1个回答

2
这是我的方法,远非解决方案,而是一种hack方法。
# Print a venn and save it to an object
a <- venn(list(letters[1:5], letters[3:8]))
# save the intersections
b <- attr(a, "intersections")

# find the coordinates
s <- seq(0,500,100); abline(h=s); text(s, y=s, x=0)
s <- seq(0,500,50);  abline(v=s); text(s, y=0, x=s)

enter image description here

# the hack, destroy the venn to avoid the plotting of the internal numbers 
rownames(a) <- letters[1:nrow(a)]
a
plot.venn(a)
>Error in data[n, 1] : subscript out of bounds

# include the internal labels
text(200,300,paste(b$`01`,collapse = "\n"))
text(200,200,paste(b$`11`,collapse = "\n"))
text(200,100,paste(b$`10`,collapse = "\n"))

输入图像描述

如果有多个维恩图,它会变得很烦人。否则,您可以将维恩图保存为.svg文件,并使用inkscape或类似软件进行编辑,或通过电子邮件向开发人员询问。

编辑: 如果您的图表始终相同,则可以检查维恩函数的源代码(在RStudio中按下F2),然后复制并粘贴4和5圆维恩图的位置,并将标签函数lab("1000", data)替换为所需的标签。

对于4个圆:

      text(35, 250, lab("1000", data))
      text(140, 315, lab("0100", data))
      text(260, 315, lab("0010", data))
      text(365, 250, lab("0001", data))
      text(90, 280, lab("1100", data), cex = small)
      text(95, 110, lab("1010", data))
      text(200, 50, lab("1001", data), cex = small)
      text(200, 290, lab("0110", data))
      text(300, 110, lab("0101", data))
      text(310, 280, lab("0011", data), cex = small)
      text(130, 230, lab("1110", data))
      text(245, 75, lab("1101", data), cex = small)
      text(155, 75, lab("1011", data), cex = small)
      text(270, 230, lab("0111", data))
      text(200, 150, lab("1111", data))

编辑

现在,我会转向使用ggplot解决方案。

ggVennDiagram::ggVennDiagram(x)

enter image description here


我需要生成许多这些图表,您的建议需要对每个图表进行关注,而我最初不想花费这样的精力。只有在真正需要时,我才会这样做。但还是谢谢您的建议,这是一种方法。这两个函数都允许您获取每个交叉点中的每个元素,它们只是不能以更具展示性的方式将它们放入图表中。 - CAOC

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接