4
votes

I would like to express the edges between vertices 1 and 2 in the following graph as two separate edges with arrows in opposite directions.

require(igraph) 
e <-  c(1,2, 2,3, 3,1, 3,4 , 4,1 , 2,1)
g <- graph(e, n=5, directed = TRUE)
tkplot(g, layout=layout.circle )

What I get is just one edge with an arrow on both ends. It should be easy but I haven't found it anywhere and can't figure it out. Any idea?

1
I could only think about edge.curved=rep(0.5, ecount(g)) which makes curved edges but I would like them straight.CaffeRistretto
I think igraph support multple edges between nodes--maybe try to create two directional edges in opposite directions?Ott Toomet
Directional edge? in e <- c(1,2, 2,3, 3,1, 3,4 , 4,1 , 2,1) there is edge from 1 to 2 (first two) and also from 2 to 1 (last two). Or what do you mean by directional edges?CaffeRistretto
Yes, this is what I mean. But I haven't tried it myself...Ott Toomet
That's two separate edges. igraph just happens to draw them on top of each other, so you see them as a single edge with two arrowheads. Unfortunately there's no way in igraph to draw them as two straight edges, so your best bet is still edge.curved. You can set it to 0.0 for "single" edges and 0.5 for edges that exist in both directions.Tamás

1 Answers

1
votes

You should plot the graph with curved edges. Note that in plot(), you curve with edge.curved, but edge-attributes to individually curve edges should be curved only.

The below function curve.reciprocal.edges() I wrote after finding this answer by Sacha Epskamp who apparently has written a package, qgraph, which you might find useful to explore if your needs exceed what can be achieved by this:

require(igraph)
e <-  c(1,2, 2,3, 3,1, 3,4 , 4,1 , 2,1)
g <- graph(e, n=5, directed = TRUE)

curve.reciprocal.edges <- function(g, curve=.3){
    # Return a graph where the edge-attribute $curved is reset to highlight reciprocal edges
    el <- t(apply(get.edgelist(g),1,sort))
    E(g)$curved <- 0
    E(g)[duplicated(el) | duplicated(el,fromLast =TRUE)]$curved <- curve
    (g)
}

plot(g, layout=layout.circle, edge.curved=.2)
plot(curve.reciprocal.edges(g), layout=layout.circle)