使用igraph,当箭头指向相反方向时如何强制曲率 [英] Using igraph, how to force curvature when arrows point in opposite directions

查看:116
本文介绍了使用igraph,当箭头指向相反方向时如何强制曲率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

autocurve.edges在弯曲igraph图中的边缘方面做得非常出色,以使它们在指向相同方向时不会重叠.但是,当它们指向相反的方向时,不会应用任何曲率.

autocurve.edges does an amazing job of curving edges in igraph plots so that they don't overlap when they point in the same direction. However, when they point in opposite directions, no curvature is applied.

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

问题出在b和c(或c和b)之间的箭头上.

The issue is for the arrows between b and c (or c and b).

除了手动指定曲率外,还有其他建议吗?

Other than specifying curvature manually, any suggestions?

推荐答案

我将edge.curved选项与autocurve.edges使用的相同seq调用一起使用.

I would use the edge.curved option with the same seq call that autocurve.edges uses.

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

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

As Étienne pointed out, this solution also curves edges for unique observations. The solution is then to modify the autocurve.edges function. This is my modified function called autocurve.edges2. Basically, it generates a vector, which curves only non-unique edges.

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)时的结果:

And here's the result when adding a single, non-mutual edge (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)

这篇关于使用igraph,当箭头指向相反方向时如何强制曲率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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