rplotigrapharrows

Double Arrows in igraph and legible lettering


#Dataframe 
Netzwerkgraph <- graph.data.frame(Datensatz[,1:3], directed = TRUE)

#vectors
actors<-Datensatz$Von
relations<-Datensatz$Nach
weight<-Datensatz$Nachrichten

plot(Netzwerkgraph,vertex.color="lightblue", edge.arrow.size=0.5, edge.lty=1,arrow.mode=3, edge.label=weight, edge.label.cex=0.4)

Network Analysis: (https://i.sstatic.net/nEVCi.png)

I would like to avoid the double arrows at the end of some edges. I would like to see, instead, two different edges. Also I want the labeling of the arrows to be legible and not overlapping


Solution

  • You can use the argument edge.curved in your plot statement. You do not provide any data, so I will just generate some random graph to illustrate.

    library(igraph)
    
    set.seed(76)
    g = erdos.renyi.game(10, 0.25, directed=T)
    
    Curve = rep(0, ecount(g))
    Curve[which(duplicated(rbind(ends(g, E(g)), 
                    ends(g, E(g))[,2:1]))) - 
                    ecount(g)] = 0.4
    plot(g, edge.curved = Curve)
    

    Graph with some edges curved

    The slightly complicated definition of Curve has a simple intention. If there is an edge from A to B but not B to A, make Curve = 0 to get a straight edge. If there is an edge in both directions, make Curve be 0.4

    This is better, but with the nodes placed just anywhere, the edges are still a little hard to see. You can use tkplot to plot the graph and move the nodes to make the graph look nice, then capture the layout using tkplot.getcoords and plot again using the nicer layout. For this graph I got:

    TKP = tkplot(g, edge.curved = Curve, vertex.color="orange")
    LO = tkplot.getcoords(TKP)
    plot(g, edge.curved = Curve, layout=LO)
    

    Same graph with a better layout