challenge1
Miranda Manka
Author

Miranda Manka

Published

February 22, 2023

Code
library(tidyverse)
library(igraph)

knitr::opts_chunk$set(echo = TRUE)

Challenge Overview

Today’s challenge is to

  1. read in a dataset, and

  2. create a network object

Load the Data

Code
got_marriages = read_csv("_data/got/got_marriages.csv", show_col_types = FALSE)
got_marriages
# A tibble: 255 × 5
   From      To        Type    Notes  Generation
   <chr>     <chr>     <chr>   <chr>  <chr>     
 1 Targaryen Stark     Married R+L=J  Current   
 2 Baratheon Martell   Engaged died   Current   
 3 Baratheon Stark     Engaged broken Current   
 4 Martell   Essos     Married <NA>   Current   
 5 Martell   Reach     Affair  <NA>   Current   
 6 Martell   Essos     Affair  <NA>   Current   
 7 Martell   Essos     Affair  <NA>   Current   
 8 Martell   Septa     Affair  <NA>   Current   
 9 Martell   Dorne     Affair  <NA>   Current   
10 Martell   Targaryen Married <NA>   Current   
# … with 245 more rows

Create a Network

The network is undirected, unweighted, and unimodal. There are 20 vertices/nodes (families) and 255 edges/links (different connections/relationships).

Code
got_marriages.ig = graph_from_data_frame(got_marriages, directed = FALSE) #directed = false because with relationships, if a is married to b then b is also married to a
got_marriages.ig
IGRAPH 3af7a91 UN-- 20 255 -- 
+ attr: name (v/c), Type (e/c), Notes (e/c), Generation (e/c)
+ edges from 3af7a91 (vertex names):
 [1] Targaryen--Stark       Baratheon--Martell     Baratheon--Stark      
 [4] Martell  --Essos       Martell  --Reach       Martell  --Essos      
 [7] Martell  --Essos       Martell  --Septa       Martell  --Dorne      
[10] Targaryen--Martell     Targaryen--Essos       Targaryen--Essos      
[13] Baratheon--Lannister   Baratheon--Vale        Baratheon--Riverlands 
[16] Baratheon--Crownlands  Baratheon--Reach       Baratheon--Westerlands
[19] Baratheon--Crownlands  Lannister--Lannister   Baratheon--Reach      
[22] Baratheon--Tyrell      Tyrell   --Reach       Tyrell   --Reach      
+ ... omitted several edges
Code
vcount(got_marriages.ig)
[1] 20
Code
ecount(got_marriages.ig)
[1] 255
Code
is_bipartite(got_marriages.ig)
[1] FALSE
Code
is_directed(got_marriages.ig)
[1] FALSE
Code
is_weighted(got_marriages.ig)
[1] FALSE
Code
table(got_marriages$Type)

 Affair Engaged Married 
     36       2     217 
Code
plot(got_marriages.ig)