Quick overview of igraph [r]

Igraph is one of the most used packages in R for the analysis of graph and networks. In this post, it is presented a quick overview of the package.

 

To have more information about the package:

To have more technical explanations of Network Analysis in R:

## Download and install the package
install.package(igraph)

## Load the package
library(igraph)

## Create a graph
g = graph.formula(1-2,2-3)

## Plot your first network!
plot(g)

## Incorporate color to the vertex
V(g)$color=V(g)$name
V(g)$color=gsub("1","blue", V(g)$color) 
V(g)$color=gsub("2","red", V(g)$color)
V(g)$color=gsub("3","blue", V(g)$color)

## Color to the edges
E(g)$color = "black"

## Plot
set.seed(19)
plot(g, vertex.label = NA, vertex.size2=30, edge.width=2)

## Create a matrix
A = matrix(c(0,0,0,1,1,0,
              0,0,0,1,1,1,
              0,0,0,0,1,0,
              1,1,0,0,0,0,
              1,1,0,0,0,0,
              0,0,0,0,0,0), 6,6)
A

## Characteristics of the matrix
is.matrix(A)
dim(A)

## Igraph object from matrix
matrix = graph.adjacency(A)

## Plot the matrix!
plot(matrix)

Translate »