challenge_1
instructions
Loading Game of Thrones marriages and Creating a Network
Author

Bryn Kruzlic

Published

February 28, 2023

Load in libraries

Code
# load in libraries
knitr::opts_chunk$set(echo = TRUE)
library(igraph)

Attaching package: 'igraph'
The following objects are masked from 'package:stats':

    decompose, spectrum
The following object is masked from 'package:base':

    union

Load in data set. This is the Game of Thrones marriages dataset

Code
# read in data set

library(readr)
got_marriages <- read_csv("_data/got/got_marriages.csv")
Rows: 255 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (5): From, To, Type, Notes, Generation

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Code
View(got_marriages)

Create a Network

Code
# plot the marriages using igraph

#| label: summary
marriages.ig <- graph_from_data_frame(got_marriages, directed = FALSE)
plot.igraph(marriages.ig, vertex.size=13)

Is the network directed or undirected? The answer is false.

Is the network weighted or unweighted? The answer is false.

Is the network unimodal or bipartite? The answer is false.

Code
is.bipartite(marriages.ig)
[1] FALSE
Code
is.directed(marriages.ig)
[1] FALSE
Code
is.weighted(marriages.ig)
[1] FALSE

The network is not directed, weighted, or bipartite.

Now, let’s take a look at the vertices and edges of the network.

Code
vcount(marriages.ig)
[1] 20
Code
ecount(marriages.ig)
[1] 255

According to the above code, there is a total of 20 vertices and 255 edges.

Other important factors to consider

Code
table(got_marriages$Type)

 Affair Engaged Married 
     36       2     217 
Code
table(got_marriages$Generation)

Current    Past 
    125     130 
Code
table(got_marriages$From)

      Arryn   Baratheon  Crownlands        Frey   Lannister     Martell 
          6          15           5          47          22           9 
      North       Reach  Riverlands       Stark  Stormlands   Targaryen 
         13          16           5          27           1          65 
      Tully      Tyrell        Vale Westerlands 
          2           8          11           3