I've been trying to use the igraph
package in R to graph a network where every pair of nodes has a weighted relationship between -4 and 4 (-4 meaning "as far apart as possible") When I plotted the data initially, I was able to use the weight to annotate the link thickness, but not affect the layout. Pruning the "worst" edges helps a bit, but then causes weakly linked nodes to fall off the graph, see #64 and #119 this example, and doesn't seem to move "low" value nodes apart very well. What I want, eventually, is to have the nodes plotted as close to "similar" nodes, and as far from different nodes. (edit: changing the Weight
to weight
in the datafile has helped, will reformulate question to more clearly ask)
my code is and I sample datefiles are here: https://www.dropbox.com/s/kuqo3a8twa149gd/paris_rouen.zip?dl=0
datefile_base <- "paris_rouen_utrecht"
nodes <- read.csv(paste(datefile_base, "-nodes.csv", sep=""), header=T, as.is=T)
links <- read.csv(paste(datefile_base, "-edge.csv", sep=""), header=T, as.is=T)
library(igraph)
require(stats)
net <- graph_from_data_frame(d=links, vertices=nodes, directed=F)
simplify(net, edge.attr.comb=list(weight="sum","ignore"))
translucent <- rainbow(5, alpha=.5)
V(net)$color <- translucent[V(net)$UseNumber]
plot.new
cut.off <- quantile(links$Weight)["75%"]
net.sp <- delete_edges(net, E(net)[Weight<cut.off])
layout_with_fr(net.sp)
plot(net.sp)
legend("topleft", c("Paris","Rouen", "Utrecht", "Unknown"), pch=21,
col="#777777", pt.bg=translucent, pt.cex=2, cex=.8, bty="n", ncol=1)