函数calculate.overlap来自VennDiagram包

时间:2016-02-17 17:30:50

标签: r venn-diagram

编辑:我有以下两个清单。它们的写法完全按照它们的呈现方式编写:

x1 <- list()
x1$A <- as.character(c("Per_36","Cent","CeM","vDG","LAVL","RSGd"))
x1$B <- as.character(c("vCA1","DLE","Per_36","vDG","DIE","Per_35"))
x1$C <- as.character(c("vCA1","Cg1","LAVL", "RSGc", "RSGd","Per_35","Per_36"))
x1$D <- as.character(c("Por","Cg1","RSGc","LAVL","Per_35","RSGd","Per_36"))

x2 <- list()
x2$A <- as.character(c("Per_36","Per_35","Por","vCA1","BLV","Cent","PrL"))
x2$B <- as.character(c("BLA","VIE","BLV","Por","Cent","Ment","dCA1"))
x2$C <- as.character(c("dDG","Per_36","CeM","Per_35","BLV","dCA1","PrL","IL"))
x2$D <- as.character(c("CeC","RSGb","CeL","dDG","CeM","dCA1","PrL","IL"))

它们以完全相同的方式生成。当我从x1中的calculate.overlap包运行函数VennDiagram时,我得到一个很好的情节,并且该函数运行完美。但是当我在x2中运行时,我得到一个空列表,这显然是错误的。我只是看不出它有什么问题。任何帮助?

overlapx1
$a6
[1] "Per_36"

$a12
character(0)

$a11
character(0)

$a5
[1] "LAVL" "RSGd"

$a7
[1] "Per_35"

$a15
[1] "vDG"

$a4
character(0)

$a10
character(0)

$a13
[1] "vCA1"

$a8
character(0)

$a2
[1] "Cg1"  "RSGc"

$a9
[1] "Cent" "CeM" 

$a14
[1] "DLE" "DIE"

$a1
character(0)

$a3
[1] "Por"

当我运行overlapx2 <- calculate.overlap(x2)时,我得到一个包含列表所有向量的相等列表= character(0)

编辑2:包裹的链接如下 https://cran.r-project.org/web/packages/VennDiagram/index.html

手册 https://cran.r-project.org/web/packages/VennDiagram/VennDiagram.pdf

作者是Hambo Chen,但由Paul Boutros维护

1 个答案:

答案 0 :(得分:1)

我挖掘了函数中的代码并发现了错误。

我将发布一个代码示例,可以作为我自己问题的答案和解决方案。

calculate.overlap
function (x) 
{
    if (1 == length(x)) {
        overlap <- x
    }
    else if (2 == length(x)) {
        overlap <- list(a1 = x[[1]], a2 = x[[2]], a3 = intersect(x[[1]], 
            x[[2]]))
    }
    else if (3 == length(x)) {
        A <- x[[1]]
        B <- x[[2]]
        C <- x[[3]]
        nab <- intersect(A, B)
        nbc <- intersect(B, C)
        nac <- intersect(A, C)
        nabc <- intersect(nab, C)
        a5 = nabc
        a2 = nab[-which(nab %in% a5)]
        a4 = nac[-which(nac %in% a5)]
        a6 = nbc[-which(nbc %in% a5)]
        a1 = A[-which(A %in% c(a2, a4, a5))]
        a3 = B[-which(B %in% c(a2, a5, a6))]
        a7 = C[-which(C %in% c(a4, a5, a6))]
        overlap <- list(a5 = a5, a2 = a2, a4 = a4, a6 = a6, a1 = a1, 
            a3 = a3, a7 = a7)
    }
#. Purposely took the length(x) == 4 and 5 to shorten it. 
#. rationale is the same ans is simple
#.
    else {
        flog.error("Invalid size of input object", name = "VennDiagramLogger")
        stop("Invalid size of input object")
    }
}
<environment: namespace:VennDiagram>

错误操作是下面突出显示的命令:

a2 = nab[**-which(**nab %in% a5)]

将其替换为

a2 = nab[! nab %in% a5]

诀窍就好了。但必须在函数的所有操作中完成。

我会尝试联系该软件包的作者,看看他是否可以在将来更新它。