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 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")
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 <- read_graph(file = "polblogs/polblogs.gml",format = "gml")
deg <- degree(graph, mode = "out")
idx <- which(deg >70)
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)*1
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",linkDistance = 300,
height =800,
width = 800,fontSize = 14,opacity = 1,zoom = TRUE,bounded = TRUE,opacityNoHover = 0.8,linkColour = "lightgray",linkWidth = 0.2,legend = TRUE)