Chapter 2 Exploring the Network
2.1 Data
The dataset used dates back from 2019 to 2020. It was gathered in a series of tables forming a package called uspolitician2020
.
It includes a table usp2020
with the following columns:
name
screen_name
class
categorical variable representing Presidential Cabinet (P), Senate (S), House of Representatives (R)role
, categorical variable that assigns the role in the political system (house, senate, role in the cabinet)territory
state represented (except for Cabinet members)
It also includes a table usp2020_edges
with the following columns:
source
, the screen_name of the sourcetarget
, the screen_name of the target
First of all, we need to load the usp2020 dataset. This dataset contains the information about the individual politicians. We will use this dataset to create the nodes of our network.
utils::read.csv("dataset/usp2020.csv")
usp2020 <-head(usp2020)
## name screen_name class role party state
## 1 doug jones sendougjones S senate D alabama
## 2 lisa murkowski lisamurkowski S senate R alaska
## 3 kyrsten sinema senatorsinema S senate D arizona
## 4 martha mcsally senmcsallyaz S senate R arizona
## 5 john boozman johnboozman S senate R arkansas
## 6 tom cotton sentomcotton S senate R arkansas
usp2020 nodes <-
Second, we need to load the usp2020_edges dataset. This dataset contains the information about the following relationships between the politicians. We will use this dataset to create the edges of our network.
utils::read.csv("dataset/usp2020_edges.csv")
edges <-head(edges)
## V1 V2
## 1 realdonaldtrump jim_jordan
## 2 realdonaldtrump vp
## 3 realdonaldtrump mike_pence
## 4 potus ustraderep
## 5 potus realdonaldtrump
## 6 potus stevenmnuchin1
Now, we can create the network. In order to do that, we will use the igraph package. We will also get rid of the self-loops.
igraph::graph.data.frame(edges)
network <-# Get rid of loops
igraph::simplify(network) network <-