Background

The igraph R package is both, a library and a package of the R statistical software for creation and manipulation of graphs and analysis of networks.

This package was originally written in C programming language. It can be implemented in Python programming language, C programming language and, of course, in Open Source R. It is widely used in the academy within the discipline of Social Networks Analysis and related areas.

iGraph was developed by Gábor Csárdi and Tamás Nepusz in 2006. The source code of the different versions of this package was written in C programming languaje. The version for R is located in the official website of CRAN (Comprehensive R Archive Network) and can be installed in a very simple way with the r command for packages installation. iGraph is freely available under the GNU General Public License Version 2.

In their publication for the International Journal of Complex Systems, in where iGraph was entered, Nepusz and Csárdi affirm that “The iGraph software package provides useful tools for researchers in Social Networks Analysis. This is an Open Source portable library capable of manipulating huge graphs with millions of vertices and edges. Contains routines to create, manipulate and display networks, to calculate the structural properties, and to import and export to various file formats. Through its interfaces, it can be used with high-level languages like GNU R and Python, to support a rapid development and prototyping”.

The iGraph package has the ability to manipulate various types of data. It also has features to implement graphs algorithms without difficulty.

Among the types of data that iGraph can retrieve and read, no matter the source including the Internet, this package can read .net data types. It also has the capacity to format this data types into pajek output. To retrieve data, iGraph has the command read.graph. More conventional data, as CSV or TXT type datasets, can be retrieved with the command read.table. The package can also format the input data with the command graph.data.frame to put such data ready for analysis and graphing.


An example of the Mexican Nanotechnology Network

Dr. Eduardo Robles provided the WC.net file, which is a pajek type dataset containing the Mexican scientific community working in Nanotechnology. The dataset was uploaded in a public Dropox repository.

The next R chunk retrieves the file from such repository, loads it into an R variable and shows a summary of the data. It also shows the number of vertices with the iGraph command V() and the number of edges with the iGraph command E(). Finally, the degree of the relationships are shown with the iGraph command degree(). As it can be noticed, this network data contains 60 vertices and 300 edges.

## IGRAPH D-W- 60 300 -- 
## + attr: id (v/c), x (v/n), y (v/n), weight (e/n)
## + 60/60 vertices:
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
## [24] 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
## [47] 47 48 49 50 51 52 53 54 55 56 57 58 59 60
## + 300/300 edges:
##   [1]  1-> 1  1->27  2-> 2  2-> 8  2->46  2->55  3-> 3  3-> 4  3-> 5  3-> 7
##  [11]  3-> 9  3->11  3->12  3->13  3->14  3->19  3->27  3->33  3->48  3->54
##  [21]  4-> 3  4-> 4  4-> 7  5-> 3  5-> 5  5->14  5->33  6-> 6  6->28  6->40
##  [31]  7-> 3  7-> 4  7-> 7  8-> 2  8-> 8  8->18  9-> 3  9-> 9  9->13  9->14
##  [41]  9->22  9->37  9->44  9->48 10->10 10->14 10->44 11-> 3 11->11 11->12
##  [51] 11->27 11->48 12-> 3 12->11 12->12 12->14 12->15 12->37 12->44 12->48
##  [61] 12->49 12->51 13-> 3 13-> 9 13->13 14-> 3 14-> 5 14-> 9 14->10 14->12
##  [71] 14->14 14->18 14->20 14->22 14->33 14->36 14->37 14->38 14->39 14->41
##  [81] 14->44 14->49 14->50 14->51 14->53 14->54 14->58 15->12 15->15 15->37
##  [91] 15->49 16->16 16->33 16->44 17->17 18-> 8 18->14 18->18 18->20 19-> 3
## + ... omitted several edges
##  [1]  4  8 28  6  8  6  6  6 16  6 10 20  6 44  8  6  2  8  4 10  6  8 12
## [24]  4  2  2 10  6  2  4  6  8 16  2  6 10 30  6  8 14  8  2  2 34  8 14
## [47]  6 20 34  6 18 12  8 18 12  2  6  8  6  2

Generating Network Plots

It is possible to produce a very simple graph of the network with the command plot.igraph()

A more clear graph can be produced with parameter layout in the command plot.igraph. In this case, it is set to execute the Kamada-Kawai network algorithm.

A much more informative graph can be produced manipulating the data with a Community Newman function to identify communities by colour.

Finally, it is also possible to erase the loops to produce a much more aesthetic graph.


This work is licenced under a Creative Commons Attribution-NoDerivatives 4.0 International Licence CC BY ND