5

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 :

enter image description here

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 ?

sgibb
  • 25,396
  • 3
  • 68
  • 74

1 Answers1

7

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)

enter image description here

Hope this helps.

James Tobin
  • 3,070
  • 19
  • 35
  • Thank you, but i have already tried the qgraph function. It solves this issue but it is less usefull to adjust the parameters of the graph, for example the shape of the nodes or to adjust the text of the nodes. –  Jan 24 '14 at 15:42
  • 1
    read ?qgraph. you can change the shape of nodes by `shape='insert shape here'`. You can adjust the text of the nodes with label.cex, label.prop, label.norm, and label.scale (to name a few). – James Tobin Jan 24 '14 at 15:55
  • Ok ! And can you give a small example please ? for example, this graph with rectangular nodes and arbitrary long text in nodes ? –  Jan 24 '14 at 16:02
  • 1
    Just read ?qgraph. it has ALL the information you will need. Its not hard to play around with it and try different settings. You'll learn a lot more from it by trying the different things out. However I will give you the rectangles as a freebe :) `qgraph(df,edge.labels=T,shape='rectangle')` – James Tobin Jan 24 '14 at 16:13