Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

igraph: Specify weights in a layout algorithm

Tags:

r

igraph

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?

like image 878
CptNemo Avatar asked May 12 '26 11:05

CptNemo


1 Answers

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")
like image 82
Tamás Avatar answered May 14 '26 03:05

Tamás



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!