Vertex Labels in igraph with R

北城余情 提交于 2019-12-06 05:54:43

问题


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.



来源:https://stackoverflow.com/questions/21335944/vertex-labels-in-igraph-with-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!