Load Data
#load Data
library(readr)
library(DT)
data <- read_csv("C:/Users/lenovo/Downloads/socialnetworkdata.csv")
datatable(data)
Extract two columns of data and create a
data.frame
y <- data.frame(data$first,data$second)
datatable(y)
Create network graph. Note that a vertex is a node and an
edge is a link between vertices
require(igraph)
net <- graph.data.frame(y,directed = T)
#display vertex
V(net)
## + 52/52 vertices, named, from 8fd9f10:
## [1] AA AB AF DD CD BA CB CC BC ED AE CA EB BF BB AC DC BD DB CF DF BE EA CE EE
## [26] EF FF FD GB GC GD AD KA KF LC DA EC FA FB DE FC FE GA GE KB KC KD KE LB LA
## [51] LD LE
#label the vertex
V(net)$label < V(net)$name
## logical(0)
#add the weight, Degree represents the number of conections to a node
V(net)$degree <- degree(net)
V(net)$degree <- degree(net)
V(net)$degree
## [1] 18 9 23 36 40 26 24 50 21 27 15 62 7 12 23 27 2 4 8 12 23 20 8 10 6
## [26] 8 1 8 1 1 1 9 3 3 1 7 3 1 1 2 1 2 5 1 1 1 1 1 1 1
## [51] 1 1
#Add the weight, Degree represents the number of conections to a node
hist(V(net)$degree,
col = 'skyblue',
main = 'Histogram of Node Degree',
ylab = 'Number of Nodes',
xlab = 'Degree of Vertices')

Network Diagram Only shows connections
set.seed(222)
plot(net,
vertex.color = 'green',
vertex.size =15,
edge.arrow.size = 0.1,
vertex.label.cex =0.8)

Weighted details are in this chart
plot(net,
vertex.color = rainbow(52),
vertex.size = V(net)$degree*0.4,
edge.arrow.size = 0.1,
layout=layout.fruchterman.reingold)
