Hey guys, in this video I'm going to do a quick introduction to creating and storing a network
in a computer using a data structure called an edge list, which is one type
of data structure for networks. And so I'm going to go over this example network here
that has loops and edges and then nodes labeled a through e. And I'm going to use an edge list
to store the information about the edges and nodes in this example network. So the basic idea with an
edge list data structure for networks is that every line in your list is going to be an
edge and the list is going to be made up of two columns. The first column is going to be the node
that we're starting from. The edge starts at one node and then it goes to a destination node.
So the two columns are going to be vertex information and then if the two vertices are on the same line,
it means that there's an edge from the first vertex to the vertex in the second column. So when
we go to this example network here, we have edges that go from a to e and then we also have loops
which is where we start at one vertex and then we loop to the same vertex. We have a loop here
that starts from a to a. We have it for all the other vertices as well. If I start writing out
what this edge list would look like to represent this network, it would be a a, which is the loop.
It would be a b. This line represents the edge from a to b, so it represents this edge here. We have b b,
b c, c c, and so on. So I have the complete edge list written out here in this text file. This is a
file that has every edge and every loop in the network and this is a complete representation
of this network. If we feed this information or this data structure into a computer, it should be
able to print out or reproduce this exact network. In the next part of the video I'm going to load
in this edge list in R and then print the visualization of the network to show that
we should get the same network that we see here. Okay so I opened R and I have a short R script for
loading in the edge list data structure and then I'm going to plot the graph to show you that we're
going to get the network that we started with. The common R package that's used for doing
network analysis is called igraph. So I already installed that package. My first line of code
is just setting my working directory and this is going to be my desktop folder. My desktop folder
has my edgeless.txt file, which has my edgeless data structure information in it. I'm going to
first set my working directory. Then I'm going to load in the R package igraph and then I'm going
to load in my network as an edge list. To do that, I'm first going to load in the edgeless.txt
file that I have as a data frame using this line of code. That loads in a data frame
that I'm calling data and it has the 11 edges in my original network. And I'm saving it again as a data
frame that has two columns. The first column is the vertex that we're starting from and then the
second column points an edge from the first vertex to the final vertex in the second column.
Then after that, we're going to create an igraph graph object using this next line of code. So that's
going to be graph.data.frame and then I'm going to pass in the data frame that has the edgelist
information. This parameter "directed" is going to tell you whether the graph is a directed graph
or undirected graph. If it's false, we have an undirected graph. If you put true, it's going to be
a directed graph. Undirected means that there's no arrows when you have the edges connecting the
vertices. A directed graph will point an arrow from the first column vertex to the final column vertex,
or the second column vertex. In my original graph, the network was undirected so that's why I have
false. So I'm going to load in that line of code and then plot using the igraph package will plot
the network. I'm just going to plot my graph object g in this final line of code and then when
I do that, we get a picture of the network. So if we remember back from the first network visualization,
we see that we have the same network, just rotated. So we have basically kind of like a
square or rectangle configuration connected to a triangle and then loops at each vertex.
We have been able to recreate the network using an edge list. So this is one data structure that we
can use to represent networks in a program or in a computer and that's it for this video~
*chiptune music*