3

I found multiple postings (e.g. here and here) that illustrate how to modify a layout by adding an edge weight.

Still when I do

require(igraph)

g <- graph.ring(10)

plot(g)

set.seed(28100)
E(g)$weight <- sample(1:10, 10, replace = TRUE)
E(g)$weight 
# [1] 4 3 4 6 2 9 5 2 9 7
l <- layout_with_fr(g, weights=E(g)$weight)

plot(g, layout=l)

with R version 3.2.2 and igraph version 1.0.1 I got the exact same layout. What instead I would expect to obtain is a layout where edges with a higher (lower) weight are shorter (longer). In other words, nodes connected by an edge with a higher weight are relative closer to each other than nodes connected by a low-weight edge.

Am I doing something wrong?

Community
  • 1
  • 1
CptNemo
  • 6,455
  • 16
  • 58
  • 107
  • The layout changes slightly when I run the code. What behaviour/layout are you looking for? Please elaborate. `R version 3.2.0, graph version 1.0.1` – harre Nov 05 '15 at 18:04

1 Answers1

4

There is/was a bug in the new Fruchterman-Reingold layout implementation (starting from igraph 1.0.0) which made it ignore the weights. This has already been fixed in the development version, but it seems like this version was not released yet. You can install the development version from Github with the devtools package:

devtools::install_github("gaborcsardi/pkgconfig")
devtools::install_github("igraph/rigraph")
Tamás
  • 47,239
  • 12
  • 105
  • 124