This sample is about visualising graph data in R language

In this example A directed network of hyperlinks between weblogs on US politics, recorded in 2005 by Adamic and Glance is visualized.

Data

Data is captured from the webpage “https://networkdata.ics.uci.edu/data.php?id=102

url = "http://networkdata.ics.uci.edu/data/polblogs/polblogs.zip"
download.file(url = url,destfile = "polblogs.zip")
unzip("polblogs.zip")

User libraries

library(igraph)
## 
## Attaching package: 'igraph'
## 
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## 
## The following object is masked from 'package:base':
## 
##     union
library(networkD3)

Graph

graph <- read_graph(file = "polblogs/polblogs.gml",format = "gml")

Graph visualisation

deg <- degree(graph, mode = "out")
idx <- which(deg >60)
gn <- induced.subgraph(graph, idx)

Both <- get.data.frame(gn,what = "both")

names(Both$edges) <- c("source","target")
size<-degree(gn)/6
Both$vertices$group <- sample(0:10,max(Both$edges$source),replace = TRUE)
Both$vertices$value2 <- Both$vertices$value * 10
Both$vertices$value3 <- degree(gn)/2 + 3
Both$edges$source <- Both$edges$source -1
Both$edges$target <- Both$edges$target -1

forceNetwork(Links = Both$edges, Nodes = Both$vertices,
             Source = "source",
             Target = "target",
             NodeID = "label", Group = "group",Nodesize = "value3",
             height = 1024,
             width = 1024,fontSize = 14,opacity = 1,zoom = TRUE,bounded = TRUE,opacityNoHover = 0.2)