Introduction

This code through explores some basics of Networks as well as a deeper dive into the program DiagrammeR


Before beginning, make sure that you install DiagrammeR and load it into your library. This codethrough will also be utilizing functions from the packages dplyr and pander


Content Overview

I will demonstrate how to construct a network using data from a course discussion board. I will then show how this information may be visualized.


Why You Should Care

This topic is valuable because networks are everywhere! Think about the last 10 people you have spoken to. Now how about the last 10 people each of them spoke to. That’s a network! Now what about in the news? Networks, like the one below (found here) have been used to track the spread of disease!

Following COVID-19, many classes moved online, changing the ways we all interact. This example will look at how students interacted with one another in a class discussion board.


Learning Objectives

Specifically, you’ll learn how to…
1.) Load data into DiagrammeR as a nodelist and edgelist
2.) Graph a network
3.) Customize how the network is visualized



Definitions

Let’s start with a few definitions. For more detail, see this fabulous overview of network visualization


Nodes: Vertices in a network. These can be people, places, organizations, etc. In this example, they are students in a class identified by their initials.

Edges: Connections between nodes. These can be conversations, relationships, etc. In this example, an interaction occurred when a student posted on another student’s discussion post.


Constructing a Network

We will begin with an example created from a class discussion board.
The first data set, discussion nodes, contains the intitials of all students. It also includes some basic demographic information, such as field of interest and whether or not the student has experience in R.
The second data set, discussion edges, contains one line for each response on the second discussion board. Let’s look at the data:

##Examining Your Data

Student.ID Initials Graduate
1 UA 1
2 GB 1
3 MP 1
4 MR 1
5 BL 1
6 SW 1
Poster.ID Responder.ID
17 13
13 11
3 11
3 8
8 11
6 14


Creating a dgr_graph

In order to map a network, DiagrammeR requires graph objects of class dgr_graph. For more detailed instructions, click here

id type label shape data
1 student UA circle Economics
2 student GB circle Economics
3 student MP circle Criminal Justice
4 student MR circle Psychology
5 student BL circle Accounting
6 student SW circle Applied Linguistics
id from to rel
1 13 17 NA
2 11 13 NA
3 11 3 NA
4 8 3 NA
5 11 8 NA
6 14 6 NA


# Graph Your Network

Now that we have made our network, we should graph it

As you can see below, this is a directed network. This means that the direction of the interaction matters and is indicated by an arrow (instead of just a line).
If we look at student MP, we can see that they replied to student SK’s post. Students MO and SS relied to each other.

This graph is already pretty cool! But let’s see if we can arrange it differently.


For more information on creating network graphs, see Creating Simple Graphs from NDFs/EDFs


Customizing Our Graph

Although DiagrammeR automatically generates a network graph, we can tell it to arrange the data differently:

Networks are extremely visual! So choosing the arrangement that is best suited to your data is important!


Further Resources

Learn more about Visualizing Networks with the following:




Works Cited

This code through references and cites the following sources: