10

autocurve.edges 在 igraph 图中弯曲边缘的工作非常出色,因此当它们指向同一方向时它们不会重叠。但是,当它们指向相反的方向时,不会应用曲率。

d <- data.frame(start=c("a","a","b","c"),end=c("b","b","c","b"))


graph <- graph.data.frame(d, directed=T)

plot(graph,
     vertex.color="white")

带有指向相反方向的叠加箭头的 igraph

问题在于 b 和 c(或 c 和 b)之间的箭头。

除了手动指定曲率之外,还有什么建议吗?

4

1 回答 1

13

我会将该edge.curved选项与seqautocurve.edges 使用的调用相同。

plot(graph,
     vertex.color="white", edge.curved=seq(-0.5, 0.5, length = ecount(graph)))

在此处输入图像描述

编辑:

正如 Étienne 指出的那样,该解决方案还可以弯曲边缘以进行独特的观察。解决方案是修改autocurve.edges函数。这是我修改后的函数,称为autocurve.edges2. 基本上,它会生成一个向量,该向量仅弯曲非唯一边缘。

autocurve.edges2 <-function (graph, start = 0.5)
{
    cm <- count.multiple(graph)
    mut <-is.mutual(graph)  #are connections mutual?
    el <- apply(get.edgelist(graph, names = FALSE), 1, paste,
        collapse = ":")
    ord <- order(el)
    res <- numeric(length(ord))
    p <- 1
    while (p <= length(res)) {
        m <- cm[ord[p]]
        mut.obs <-mut[ord[p]] #are the connections mutual for this point?
        idx <- p:(p + m - 1)
        if (m == 1 & mut.obs==FALSE) { #no mutual conn = no curve
            r <- 0
        }
        else {
            r <- seq(-start, start, length = m)
        }
        res[ord[idx]] <- r
        p <- p + m
    }
    res
}

这是添加单个非相互边 (C->D) 时的结果:

library(igraph)
d <- data.frame(start=c("a","a","b","c","c"),end=c("b","b","c","b","d"))
graph <- graph.data.frame(d, directed=T)
curves <-autocurve.edges2(graph)
plot(graph, vertex.color="white", edge.curved=curves)

在此处输入图像描述

于 2013-06-01T20:01:07.707 回答