cs0815
cs0815

Reputation: 17418

change weight of edge in igraph network

I would have thought that the graph algorithm picks up the column weight in edge data frame automatically but it does not as shown in the following code:

nodes <- data.frame(name = c("1", "2", "3"), type = c("a", "b", "b"))
edges <- data.frame(from = c("1", "1"), to = c("2", "3"), weight = c(10000, 50))

net <- graph_from_data_frame(edges, directed=FALSE, vertices=nodes)
V(net)$size <- 2
V(net)$color <- ifelse(V(net)$type == "a", "darkblue", "orange")
V(net)$shape <- ifelse(V(net)$type == "a", "circle", "square")
plot(net)

Is there a way to use a specifically named column in the edge data frame (e.g. weight) to set the thickness of the depicted edges? Thanks!

Upvotes: 2

Views: 790

Answers (1)

ThomasIsCoding
ThomasIsCoding

Reputation: 102700

You can try the code below

E(net)$width <- edges$weight
plot(net)

Upvotes: 4

Related Questions