R中igraph中的R互惠边 [英] R reciprocal edges in igraph in R

查看:42
本文介绍了R中igraph中的R互惠边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 R 中处理图形.我目前正在使用 igraph,我希望能够绘制图形的双向边互惠边".到目前为止,我已经看到可以绘制双向"图​​,但不能绘制互易边,例如:E(1,3) 和 E(3,1) 可能表示为双向边 <-->,但相反,我想绘制两条平行边,一条指向另一条的相反方向 ||.在绘制plot(rEG, recipEdges = "distinct")"时,Rgraphviz 中存在一个选项,这使得这一点,但我更喜欢 igraph 上的情节.提前致谢.

解决方案

igraph 中,可以使用边属性 curved 来弯曲你想要的边.

例如,这是一个基于图的小邻接矩阵:

library("igraph")adj <- 矩阵(c(0,1,1,1,0,1,0,0,0),3,3,byrow=TRUE)图书馆(igraph")G <-graph.adjacency(adj)

节点 0 和 1 之间的边是双向的(实际上不是,它是两条边,它们看起来像双向边,因为它们是直的.):

情节(G)

要改变这一点,我们可以使用边缘列表:

E <- t(apply(get.edgelist(G),1,sort))E(G)$曲线<- 0E(G)[重复(E) |重复(E,fromLast =TRUE)]$curved <- 0.2情节(G)

<小时>

另一个选项是我的包,这是默认行为:

library("qgraph")qgraph(adj)

可以用 bidirectional 参数抑制.

I am working with graphs in R. I am currently using igraph and I would like to be able to plot bidirectional edges "reciprocal edges" of a graph. So far I've seen it is possible to plot "bidirectional" graphs but not reciprocal edges, for example: E(1,3) and E(3,1) could potentially be represented as a bidirectional edge <-->, but instead I would like to plot two parallel edges one pointing to the opposite direction of the other || . There exist in Rgraphviz an option when plotting "plot(rEG, recipEdges = "distinct")" that makes this, but I like more how plots look like on igraph. Thanks in advance.

解决方案

In igraph, you can use the edge attribute curved to curve the edges you want.

For example, here is a graph based small adjacency matrix:

library("igraph")
adj <- matrix(c(
    0,1,1,
    1,0,1,
    0,0,0),3,3,byrow=TRUE)

library("igraph")
G <- graph.adjacency(adj)

The edge between node 0 and 1 is bidirected (Actually, it isn't, it are two edges and they just look like a bidirected edge because they are straight).:

plot(G)

To change this, we can use the edgelist:

E <- t(apply(get.edgelist(G),1,sort))

E(G)$curved <- 0
E(G)[duplicated(E) | duplicated(E,fromLast =TRUE)]$curved <- 0.2

plot(G)


Another option is my package, where this is the default behavior:

library("qgraph")
qgraph(adj)

which can be suppressed with the bidirectional argument.

这篇关于R中igraph中的R互惠边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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