1. What are social networks?
Welcome to this DataCamp course on social network analysis in R. In this course you are going to learn how to use the igraph package to create, analyze and visualize social network data.
2. What are social networks?
A network graph depicts interconnections between individuals.
The presence or absence of each interconnection indicates whether there exists some form of relationship between each pair of individuals.
Many different patterns of relationships may be illustrated as a social network.
For instance the graph you are looking at may represent friendships between individuals, flight routes between cities, or even neural connections between brain regions.
The term social network may refer to the visualization of the network graph or the underlying data that makes up the graph.
In this course we will use vertex to refer to individuals, although they are also termed nodes by many people. The interconnections between individuals or vertices are called edges.
3. Network data: adjacency matrix
The network visualization is based upon underlying data that can be represented in two structures. The first is what is called the adjacency matrix. Here we have a matrix with our vertices in rows and columns. Where there is a one in a cell this indicates that an edge exists between those two vertices. A zero indicates that there is no edge present between those two vertices.
From these adjacency matrices we can mathematically derive many insights into the structure of the network and the importance and influence of key vertices.
4. Network data: edgelist
A second data structure that our network can be organized as is what is called an edgelist. This is a two column matrix or data frame. Each row represents an edge between the two individual vertices in each column.
This type of raw data is the most common form that people collect before starting social network analysis.
5. The igraph R package
There are several packages for working with network data and visualizing networks in R. In this course you will be using the igraph R package.
The first step is to create an igraph object. This can be done directly from raw data. Say you have the edgelist on the left. Using the graph-dot-edgelist() function, supply the raw data as a two column matrix as the first argument. The second argument specifies that the graph is undirected. We shall discuss this further in the next section.
When you inspect the graph object, g, it provides several pieces of information. Of note are the two numbers on the first line. The first number indicates that there are 7 vertices in the network. The second number indicates that there are 7 edges. Also useful is the final row which shows all the edges in the network.
6. igraph objects
It is possible to get lots of information directly from the igraph object. The function V() will return all vertices in a network. The function E() returns all edges.
To find the total number of vertices or edges in a network you can also use the functions gorder() and gsize() respectively.
To generate a quick and simple visualization of the network, supply the graph object to the function plot.
7. Let's practice!
Now it's your turn.