In this set of exercises we shall create an empty graph and practice the functions for basic manipulation with vertices and edges, using the package `igraph`

. If you don’t have the package already installed, install it using the following code:

install.packages("igraph")

and load it into the session using the following code:

library("igraph")

before proceeding. You can find more info about the package and graphs in general here

Answers to the exercises are available here.

If you have different solution, feel free to post it.

### The Comment section for this post is currently not working, we are looking into the problem ###

**Exercise 1**

Create an empty directed graph with 5 nodes. Set color of all nodes to yellow and shape to sphere.

**Exercise 2**

Add the following edges to the graph: 1->2, 1->3, 2->4, 3->4, 4->5.

**Exercise 3**

Add a vertex to the graph, color it to red and add edges: 3->6, 6->5. Set vertex shape to sphere.

**Exercise 4**

Replace edge 1->3 with the edge 3->1.

**Exercise 5**

Name vertices with letters A-F. List all vertices and edges.

**Exercise 6**

What is the shortest path between vertices A and E.

**Exercise 7**

Plot the graph. The size of a vertex should depend on the number of incoming edges.

**Exercise 8**

Plot the distribution of vertices degrees.

**Exercise 9**

Create a heatmap from the data.

**Exercise 10**

Create graph from subset of vertices with 1 or more incoming edges and plot it. Set the vertice shape to green box. The size of a vertice should depend on the number of outcoming edges.

**What's next:**

- Explore all our (>1000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below