2
votes

How can I normalize the plot of a weighted network in igraph where the edges are not too thick according to the edge weight?

1

1 Answers

3
votes

In igraph, where g is the graph object, you an access edge weights via E(g)$weight and modify edge weights via assignment: E(g)$weight <- new_values.

To normalize between 0-1 try: E(g)$weight <- E(g)$weight / max(E(g)$weight).

Here's a reproducible example you can copy and paste.

library(igraph)

set.seed(1) # reproducibility

# generate random graph
g <- sample_k_regular(10, k = 3, directed = FALSE, multiple = FALSE) 

# add edge weights
E(g)$weight <- sample(c(1,10,50), length(E(g)), replace = TRUE)

# view the problem
plot(g, edge.width = E(g)$weight)

enter image description here

# normalize the edge weights between 0-1
E(g)$weight <- E(g)$weight / max(E(g)$weight)

# play with different values of `k` until you get a reasonable looking graph
k = 9
plot(g, edge.width = E(g)$weight * k)

enter image description here