Code
library(tidyverse)
library(igraph)
::opts_chunk$set(echo = TRUE) knitr
Miranda Manka
February 22, 2023
Today’s challenge is to
read in a dataset, and
create a network object
# 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
The network is undirected, unweighted, and unimodal. There are 20 vertices/nodes (families) and 255 edges/links (different connections/relationships).
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
[1] 20
[1] 255
[1] FALSE
[1] FALSE
[1] FALSE
Affair Engaged Married
36 2 217
---
title: "Week 1 Challenge"
author: "Miranda Manka"
desription: "Loading Data and Creating a Network"
date: "02/22/2023"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
categories:
- challenge1
- Miranda Manka
---
```{r}
#| label: setup
#| warning: false
#| message: false
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
```{r}
got_marriages = read_csv("_data/got/got_marriages.csv", show_col_types = FALSE)
got_marriages
```
## Create a Network
The network is undirected, unweighted, and unimodal. There are 20 vertices/nodes (families) and 255 edges/links (different connections/relationships).
```{r}
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
vcount(got_marriages.ig)
ecount(got_marriages.ig)
is_bipartite(got_marriages.ig)
is_directed(got_marriages.ig)
is_weighted(got_marriages.ig)
table(got_marriages$Type)
plot(got_marriages.ig)
```