--- title: "Introduction to Business Data Analytics" subtitle: "Network Science" author: "University of Tartu" output: prettydoc::html_pretty: null highlight: github html_document: default html_notebook: default github_document: default theme: cayman --- ```{r global_options, include=FALSE} knitr::opts_chunk\$set(warning=FALSE, message=FALSE) ``` ```{r setup, echo=FALSE} library(knitr) ``` Today we are going to do some network analysis. The goals of our lab session: * Get familiar with the graphs and how to work with them; * Analyse the data about media companies. Figure out their connections; * Learn about various way of displaying statistic on the graphs. ## Libraries Today we will need following libraries: ```{r eval=FALSE} install.packages("igraph") ``` ```{r warning=FALSE} library("igraph") library("ggplot2") ``` Igraph is a package for creating and manipulating graphs and analyzing networks. There are a number of different software packages available for this purpose, but iGraph has become perhaps the most flexible and powerful library for performing network analysis. ## Basic work with networks ### Creating networks Let's create an undirected graph with 3 edges. ```{r} g1 <- graph(edges=c(1,2, 2,3, 3, 1), n=3, directed=F) plot(g1) ``` On the plot above we have 3 nodes (1,2,3) and undirected edges that connect nodes next way: **1->2, 2->3, 3->1**. Now we can study our graph simply by calling the variable: ```{r} g1 ``` Above we can find some important information about the graph: * First number - the number of nodes * Second number - the number of edges in the graph * List of edges Now let us create another graph: ```{r} g2 <- graph(edges=c(1,2, 2,3, 3,1, 4,5, 8,5, 4,7, 2,6), n=8) g2 ```
How much nodes and edges does this graph have?