R reciprocal edges in igraph in R
Asked Answered
E

2

4

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.

Ellie answered 19/4, 2011 at 4:17 Comment(0)
J
5

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.

Jacquelinejacquelyn answered 19/4, 2011 at 16:46 Comment(1)
Thanks so much, I see you can even set up the separation between parallel edges, that is great.Ellie
W
2

Try plot(graph, edge.curved=TRUE). It definitely works in igraph 0.6, and it may also work in igraph 0.5.4 (not sure when it was added).

Waldon answered 19/4, 2011 at 6:41 Comment(1)
this is great, what I liked of @sachaepskamp 's answer is that you are able to modify between-edges separation, thanks to both.Ellie

© 2022 - 2024 — McMap. All rights reserved.