Vertex Labels in igraph with R

2020-07-17 08:27发布

问题:

I have some issue while adding vertex labels in a weighted igraph working with R.

The data frame of the graph is:

df <- read.table(text=
    "From, To, Weight
    A,B,1
    B,C,2
    B,F,3
    C,D,5
    B,F,4
    C,D,6
    D,E,7
    E,B,8
    E,B,9
    E,C,10
    E,F,11", sep=',',header=TRUE)

#    From To Weight
# 1     A  B      1 
# 2     B  C      2
# 3     B  F      3
# 4     C  D      5
# 5     B  F      4
# 6     C  D      6
# 7     D  E      7
# 8     E  B      8
# 9     E  B      9
# 10    E  C     10
# 11    E  F     11

and I use :

g<-graph.data.frame(df,directed = TRUE)
plot(g)

to plot the following graph :

One can see that vertex labels (for example) from E to B are superimposed. (The same problem appears for vertex C-D and vertex B-F)

I'd like to know how to separate these labels so as to have each different weight on each vertex ?

回答1:

try the qgraph package. qgraph builds on igraph and does a lot of stuff for you in the background.

install.packages('qgraph')
require(qgraph)
qgraph(df,edge.labels=T)

Hope this helps.



标签: r igraph