R中igra中的R倒数边 [英] R reciprocal edges in igraph in R

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

问题描述

我在R中使用图。我目前使用的是igraph,我希望能够绘制图的双向边倒数边。到目前为止,我已经看到可以绘制双向图​​形而不是倒易的边缘,例如:E(1,3)和E(3,1)可能被表示为双向边缘,但是我想绘制两条平行的边,一条指向另一条||的相反方向。
当绘制绘图(rEG,recipEdges =distinct)时,Rgraphviz中存在一个选项,但我更喜欢igraph上的绘图。在$ igraph 中,您可以使用边缘属性曲线来曲线您想要的边。

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

/ b>

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

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

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

  plot(G )

要改变这种情况,我们可以使用边界列表:


$ b (G),1(排序))

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

plot(G)






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

  library(qgraph)
qgraph(adj)

可以使用双向参数进行压缩。


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中igra中的R倒数边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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