This is part 1 of a series in analyzing and visualizing network data using iGraph. The rest of the series can be found here.

Graph Theory, or network analysis as it is often called, is the mathematical portrayal of a series of edges and vertices. To contextually picture a network, think of each node being an individual on Facebook, and an edge being present between two individuals indicating the two are friends on Facebook. Through computational advancements, in-depth analysis is now possible on large social networks, with applications appearing in fields such as biology, sociology, and ecology.

The uses of graph theory are endless. Within the subject domain sit many types of graphs, from connected to disconnected graphs, trees, and cyclic graphs. Before working through these exercises, it may be useful to quickly familiarize yourself with some basic graph types here if you are not already mindful of them.

The aim of this introductory tutorial is to familiarize the reader with the iGraph package by creating some simple graphs, classifying types of graphs, and reporting some simple statistics from example graphs. It is important to understand the methods and functions being called from the iGraph package – the built-in documentation here are extensive and well documented.

Answers to the exercises are available here.

**Exercise 1**

Load the iGraph library and create an undirected star graph with 5 nodes and plot the graph.

**Exercise 2**

Add edges between the following node pairs:

<

- 8 and 5
- 6 and 3
- 6 and 10
- 5 and 2
- 4 and 8
- 2 and 7
- 6 and 5
- 7 and 9

**Exercise 3**

Re-plot the graph, this time with a circular layout, ordered by vertex number. Hint: use the layout_in_circle function.

**Exercise 4**

Computationally verify that the graph is connected.

**Exercise 5**

Is the graph bipartite? If not, explain why.

**Exercise 6**

Find the graph’s average degree. Do not use iGraph’s built-in function.

**Exercise 7**

Calculate the graph’s diameter.

**Exercise 8**

Find the size of each clique in the graph. Hint: Use the sapply function.

**Exercise 9**

Make a new plot of the graph, this time with the node size being relative to the nodes closeness, multiplied by 500.

**Exercise 10**

Color the nodes of the graph: even nodes blue, odd nodes red. Hint: Using an if-else statement will make this more concise.

## Leave a Reply