#install.packages("igraph")
library(igraph)
g <- graph(c(1,2,2,3,3,4,4,1),
directed = T,
n=7)#n is the number of nodes
plot(g,vertex.size=40,
vertex.color='green',
edge.color='red')
Directed=T
Directed =F
g[]
node 1 is related to 2 and 4 , similarly for other nodes the matrix can be seen as above
Now, let us consider an example of Instagram following among some individuals
Let's see who follows whom on Instagram and who follows back
g2
D means directed graph and N is for names
NETWORK MEASURES
degrees
Diameter is 2 for this case
edge_density(g2, loops = F)
ecount(g2)/(vcount(g2)*(vcount(g2)-1))
#0.4166667
reciprocity(g2)#calculates % of ties in directed graphs,proportion of mutual connections
#0.4
closeness(g2,mode='all',weights=NA)#closeness centrality measures how many steps is required to access every other vertex
#from a given vertex
Closeness, Highest for Li since Li is the closest to all of them
betweenness(g2,directed=T,weights=NA)# vertex or edge betweeness is the number of shortest paths going through a vertex or an edge