Friday, January 23, 2015

Visualizing Internet ... Interactivity

GraphNetwork

Visualizing Internet … Interactivity

I found a new R package called networkD3 that gives interactivity to network graphs using D3.js.
We need to manipulate the data because the forceNetwork function only allow a list of numbered edges starting in 0. We are going to use a simple trick, using the write.graph function from igraph and the edgelist format it writes the links in this way, so we only need to read the file again to a new variable.
library(igraph)

write.graph(bsk,file ="countrySG.edges", format = "edgelist")
Links<-read.table("countrySG.edges")
Let’s look the graphs from Singapur and Ukraine this way

Singapur

library(networkD3)

forceNetwork(Links = Links, Nodes = MisNodes, Source = "V1",
             Target = "V2", NodeID = "name",
             Group = "group", opacity = 0.4)

Ukraine

forceNetwork(Links = Links, Nodes = MisNodes, Source = "V1",
             Target = "V2", NodeID = "name",
             Group = "group", opacity = 0.4)
Cool graphs with only a few lines of code.