Vertex labels in igraph with R

I have a problem adding vertex labels in a weighted graph working with R.

Graph data frame:

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 build the following graph:

enter image description here

You can see that the vertex labels (for example) from E to B overlap each other. (The same problem occurs for vertex CD and vertex BF)

I would like to know how to separate these shortcuts so that each different weight on each vertex?

+4
source share
1 answer

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

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

enter image description here

Hope this helps.

+7
source

Source: https://habr.com/ru/post/1523546/


All Articles