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:
and load it into the session using the following code:
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.
Create an empty directed graph with 5 nodes. Set color of all nodes to yellow and shape to sphere.
Add the following edges to the graph: 1->2, 1->3, 2->4, 3->4, 4->5.
Add a vertex to the graph, color it to red and add edges: 3->6, 6->5. Set vertex shape to sphere.
Replace edge 1->3 with the edge 3->1.
Name vertices with letters A-F. List all vertices and edges.
What is the shortest path between vertices A and E.
Plot the graph. The size of a vertex should depend on the number of incoming edges.
Plot the distribution of vertices degrees.
Create a heatmap from the data.
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.