igraph package in r: edge labels are overlapping
Asked Answered
P

1

9

I am working with the igraph package in R to visualise network flows.

library(igraph)

# Example Data:
b <- c("countryA", "countryB", "countryC", "countryA", "countryC", "countryA")
c <- c("countryB", "countryC", "countryA", "countryB", "countryA", "countryB")
d<- c(100, 200, 200, 300, 400, 200)
e <- c(5,12,10,24,25,12)
mydata <- data.frame(b,c,d,e)
colnames(mydata) <- c("exporteur", "partner", "tradeflow", "price")

# Plot in igraph
mydata.igraph <- graph.data.frame(mydata)
E(mydata.igraph)$label <- mydata[,3]
plot(mydata.igraph)

As you can see, my edge labels (labels of the arrows) are overlapping. How to solve this?

Thanks in advance!

Piecework answered 17/11, 2013 at 17:5 Comment(2)
vertex.label.dist is possible but it seems not yet for edgesSlalom
You can't easily right now, you cannot customize placement of edge labels in R igraph. Take a look at the sna package, maybe that supports it, although I haven't checked, so I am not sure. If you want to plot diagrams, you can also look at the diagram package. To do it with igraph, you'll need to plot the labels as an additional step, with the text() function.Weaks
B
1

This is the code to do it. It uses the edgelist instead of the igraph, but it is a cooler looking graph.

    library(qgraph)
    qgraph(mydata,edge.labels=T)

Check out this post for a more detail

Draw Network in R (control edge thickness plus non-overlapping edges)

And this help page for using qgraph: http://rgm3.lab.nig.ac.jp/RGM/R_rdfile?f=qgraph/man/qgraph.Rd&d=R_CC

Barnaby answered 10/1, 2014 at 3:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.