本文介绍了优化的VennDiagram,带有内部标签r的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以优化的方式绘制维恩图(请参见下文),并将案例作为内部标签(而不是每个交叉点的案例数).我知道每个人都有帖子,但是没有一个解决方案允许我同时做.

I am trying to plot a venn diagram in an optimized way (see below) and with the cases as internal labels (not the number of cases in each intersection). I know there are post for each of them but non of the solutions allowed me to do both.

我有这个:

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)

我得到以下输出:

关于维恩图的组织我想这样做:

Regarding the organization of the venn diagramI want to do this:

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

.但是,在venn函数中,我似乎无法用标签名称代替计数.我使用的交集= TRUE,通过参数的说明应该可以,但是不能(尽管如果我查看变量c的内部,信息​​就在那里).

which I got from package gplots() using the venn function with simplify = TRUE. However, in the venn function, I seem to no be able to replace the counts by the names of the labels. I used the intersections = TRUE, which by the description of the argument should work, but it doesn't (although if I look inside the variable c, the info is there).

    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参数完全相同?

Question: Using VennDiagrampackage, is there a way to do exactly the same as the simplify argument does in the venn function from gplots package?

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

Question 2: Using the venn function from gplots package, is there a way to display the names of each element instead of the element counts? Like I did in the 'venn.diagram' function?

预先感谢

推荐答案

这是我的方法,到目前为止,这还没有解决方案,只是一种破解.

Here is my approach which is by far no solution rather a 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)
# 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"))

令人讨厌的是多个维恩.否则,您可以将venn保存为.svg,并使用inkscape或类似软件对其进行编辑,或者通过电子邮件询问开发人员.

It's annoying with multiple venns. Otherwise you can save the venn as an .svg and edit it with inkscape or similar softwares or ask the developer by email.

如果您的图看起来相同,则可以检查venn函数的源代码(在RStudio中,单击F2),然后复制粘贴4个和5个圆形venn的位置,并用所需的标签替换标签函数lab("1000", data).

If your plots looking alwas the same you can check the source code for the venn function (In RStudio by hitting F2) and copy paste the positions for 4 and 5 circle venns and replace the labels function lab("1000", data) with your desired labels.

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))

这篇关于优化的VennDiagram,带有内部标签r的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 06:23