Network Analysis Part 1 Exercises

September 15, 2016
By

(This article was first published on R-exercises, and kindly contributed to R-bloggers)

main-graph

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.

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.

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

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)