I've been playing around with igraph in R and am having trouble using weights when I visualize a network. I have read that this may not work with every layout type but should with Fruchterman-Reingold.
My code and output are below (I tried two different versions of the layout function, I think they are doing the same thing, but tried both just in case)
I would expect Cecil and Bob to be very close together in vers1 because of the high weighting on their relationship, but that doesn't seem to happen. Only when I create additional rows for Bob and Cecil (vers2) does this seem to occur, but that's going to be a pain for what I really want to do with a much larger data set.
I would post the images of what I'm getting, but I'm new to stack overflow and didn't have enough reputation points.
Any ideas? Thanks in advance.
Code:
#vers1
library(igraph)
relations <- data.frame(from=c("Bob", "Cecil", "Cecil", "David",
"David", "Esmeralda"),
to=c("Alice", "Bob", "Alice", "Alice", "Bob",
"Alice"),
weight=c(1,100,1,1,1,1))
graph<-graph_from_data_frame(relations, directed=F)
coords1<-layout_with_fr(graph, weights=E(graph)$weight)
coords2 <- layout.fruchterman.reingold(graph, weights=E(graph)$weight);
plot(graph,layout=coords1)
plot(graph,layout=coords2)
#vers2
library(igraph)
relations <- data.frame(from=c("Bob", "Cecil", "Cecil", "David",
"David", "Esmeralda",
"Cecil",
"Cecil",
"Cecil",
"Cecil",
"Cecil"),
to=c("Alice", "Bob", "Alice", "Alice", "Bob",
"Alice",
"Bob",
"Bob",
"Bob",
"Bob",
"Bob"),
weight=c(1,1,1,1,1,1,1,1,1,1,1))
graph<-graph_from_data_frame(relations, directed=F)
coords1<-layout_with_fr(graph, weights=E(graph)$weight)
coords2 <- layout.fruchterman.reingold(graph, weights=E(graph)$weight);
plot(graph,layout=coords1)
plot(graph,layout=coords2)