igraph 矩形顶点连接在“错误”一侧

问题描述 投票:0回答:1

我正在努力寻找一种设置来防止矩形顶点连接到错误的(又称远程)一侧。对于有向图,问题在于边的出方向和入方向。

借用这里的例子: https://stackoverflow.com/a/14473972/1114163,如果我们调整顶点的透明度,问题就会变得明显

例如,Don-Steve 和 Steve-Gery 边分别经过 Don 和 Steve。我还没有看到它发生在圆形上,但我也想修复矩形,因为它们对于具有较长文本标签的网络特别有用......(注意,问题并不特定于调整大小的顶点,同样的问题可以在为矩形设置固定宽度时可见)

camp <- graph.formula(Harry:Steve:Don:Bert - Harry:Steve:Don:Bert,
    Pam:Brazey:Carol:Pat - Pam:Brazey:Carol:Pat,
    Holly   - Carol:Pat:Pam:Jennie:Bill,
    Bill    - Pauline:Michael:Lee:Holly,
    Pauline - Bill:Jennie:Ann,
    Jennie  - Holly:Michael:Lee:Ann:Pauline,
    Michael - Bill:Jennie:Ann:Lee:John,
    Ann     - Michael:Jennie:Pauline,
    Lee     - Michael:Bill:Jennie,
    Gery    - Pat:Steve:Russ:John,
    Russ    - Steve:Bert:Gery:John,
    John    - Gery:Russ:Michael)

V(camp)$label <- V(camp)$name
set.seed(42)   ## to make this reproducable
co <- layout.auto(camp)

plot(0, type="n", ann=FALSE, axes=FALSE, xlim=extendrange(co[,1]), 
    ylim=extendrange(co[,2]))
plot(camp, layout=co, rescale=FALSE, add=TRUE,vertex.color=adjustcolor("blue",.3),
    vertex.shape="rectangle",
    vertex.size=(strwidth(V(camp)$label) + strwidth("oo")) * 100,
    vertex.size2=strheight("I") * 2 * 100)
r igraph
1个回答
0
投票

您可以使用

circle
布局来避免“错误”的连接点,例如maple

set.seed(42) ## to make this reproducable
co <- layout.circle(camp)
plot(camp,
  layout = co,
  vertex.shape = "rectangle",
  vertex.color = adjustcolor("blue", .2),
  edge.width = 2,
  edge.color = as.factor(E(camp))
)

© www.soinside.com 2019 - 2024. All rights reserved.