有没有办法在 igraph R 中为输入和输出设置单独的加权边?

Is there a way to have separate weighted edges for ins and outs in igraph R?

我正在使用 igraph 包在 R studio 中制作定向网络。我想在适用的情况下显示节点之间的两条边,均加权,一条用于输入,一条用于输出。我是 R 的新手,并设法获得了编译来龙去脉的加权边缘,但希望将它们分开。

我用谷歌搜索了我的问题,但没有结果,可能是措辞错误。如果我措辞不当,我提前道歉。

编辑: 最小可重现样本:

OPR.df <- data.frame("From" = c(c("8", "8", "8", "8", "7", "25", "24", "1A", "12", "12"),
                                c("12", "12", "12", "17", "17", "17"),
                                c("17", "17", "17", "17"),
                                c("17", "17", "17", "17", "17", "9A", "9", "17", "9", "17", "9"),
                                c("9", "17", "17", "17")),
                     "To" = c(c("8", "8", "8", "7", "25", "24", "1A", "12", "12", "12"), 
                              c("12", "12", "17", "17", "17", "17"),
                              c("17", "17", "17", "17"),
                              c("17", "17", "17", "17", "9A", "9", "17", "9", "17", "9", "17"),
                              c("17", "17", "17", "17")))


opr.d <- graph_from_data_frame(d = OPR.df,  
                             directed = T)

# I think this is the part where I set this??
E(opr.d)$weight <- 1

opr.sd <- simplify(opr.d,
            remove.multiple = T,
            remove.loops = F,
            edge.attr.comb = c(weight = "sum",
                               type = "ignore"))
E(opr.sd)$width <- E(opr.sd)$weight/3

你可以做很多事情来实现双向 链接更明显。首先,使用默认布局 crowds 进行绘图 顶点 9、9A 和 17 靠得太近了。没有空间 看到边缘。我将使用 layout_with_graphopt ,效果很好 对于这个例子,虽然对于更复杂的例子你可能需要 进一步调整布局。

set.seed(4321)
plot(opr.sd, xpd=NA)
set.seed(4321)
plot(opr.sd, layout=layout_with_graphopt)

当然,我们仍然有你原来问题的问题: 箭头相互重叠。您可以使用 edge.curved 修复此问题 争论。我希望所有的箭头都是直的 除了 重叠,所以我创建了一个自定义的曲率向量来调整 重叠的边缘。也,箭头太大了,很难 看到箭头,所以我把头做得小了一点。总之,我们得到:

CURV = rep(0,ecount(opr.sd))
CURV[2]  = 0.6
CURV[11] = 0.6
CURV[13] = 0.6

set.seed(4321)
plot(opr.sd, layout=layout_with_graphopt, 
    edge.arrow.size=0.7, edge.curved=CURV, frame=T)

您可能仍想稍微调整一下,但我认为这表明 解决问题的路径。