Social Network Analysis With Igraph Package Using R

From AIRWiki

Revision as of 13:43, 16 March 2011 by RiccardoTasso (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Install the package under R environmemnt

under Ubuntu install the R package:

sudo apt-get install r-base-core

type R to start the program:


type the command to download and install igraph as R library:


Starting with the package

don't forget to load the library:


parse a network file in Pajek format and access to its memory representation through the variable 'g':

g <- read.graph(file='/your/path/.../', format='pajek')

list vertex and their attributes of graph g:

V(g)                      # the list of all nodes
V(g)[0]                   # access the first node
list.vertex.attributes(g) # the list of all vertex attributes names
V(g)[0]$id                # access the attribute 'id' for the first node

list edges/arcs and their attributes of graph g:

E(g)                      # the list of all edges/arcs
E(g)[0]                   # access the first edge/arc
list.edge.attributes(g)   # the list of all edges/arcs attributes names
E(g)[0]$weight            # access the attribute 'weight' for the first node

draw the graph:


Macroscopic Analysis

graph size (number of nodes): length(V(g))

number of edges: length(E(g))

diameter: diameter(g)

mean degree:


giant component size (the largest connected component size):


Node Centrality Analysis

degree: degree(g)

closeness: closeness(g)

betweenness: betweenness(g)

eigenvector/pagerank: evcent(g)

Clustering Techniques

connected components: clusters(g)

edge betweenness:



References and further informations

Igraph/R documentation: