Here you will find daily news and tutorials about R, contributed by over 750 bloggers.
There are many ways to follow us - By e-mail:On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here)

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

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

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.

Related

To leave a comment for the author, please follow the link and comment on their blog: R-exercises.