Code
library(tidyverse)
library(igraph)
::opts_chunk$set(echo = TRUE) knitr
Claire Battaglia
February 22, 2023
This dataset represents the teams in Game of Thrones.
# A tibble: 25 × 5
from to alliance gh id
<chr> <chr> <chr> <dbl> <dbl>
1 Drogo follows Drogo Opportunists 0 0
2 Littlefinger follows Littlefinger Opportunists 0 1
3 Martell joins the Martells Opportunists 0 2
4 Red God worships the Red God Opportunists 0 3
5 Renly follows Renly Opportunists 0 4
6 Second Sons joins the Second Sons Opportunists 0 5
7 Stannis follows Stannis Opportunists 0 6
8 Stormcrows joins the Stormcrows Opportunists 0 7
9 Targaryen joins the Targaryens Opportunists 0 8
10 Tyrell joins the Tyrells Opportunists 0 9
# … with 15 more rows
Now I’ll create a network object.
IGRAPH b1d14af UN-- 66 33 --
+ attr: name (v/c), alliance (e/c), gh (e/n), id (e/n)
+ edges from b1d14af (vertex names):
[1] Drogo --follows Drogo Littlefinger--follows Littlefinger
[3] Martell --joins the Martells Red God --worships the Red God
[5] Renly --follows Renly Second Sons --joins the Second Sons
[7] Stannis --follows Stannis Stormcrows --joins the Stormcrows
[9] Targaryen --joins the Targaryens Tyrell --joins the Tyrells
[11] Windblown --joins the Windblown
+ ... omitted several edges
This tells us a few things.
We can explore the nodes and edges further.
+ 66/66 vertices, named, from b1d14af:
[1] Drogo
[2] Littlefinger
[3] Martell
[4] Red God
[5] Renly
[6] Second Sons
[7] Stannis
[8] Stormcrows
[9] Targaryen
[10] Tyrell
+ ... omitted several vertices
+ 33/33 edges from b1d14af (vertex names):
[1] Drogo --follows Drogo
[2] Littlefinger --follows Littlefinger
[3] Martell --joins the Martells
[4] Red God --worships the Red God
[5] Renly --follows Renly
[6] Second Sons --joins the Second Sons
[7] Stannis --follows Stannis
[8] Stormcrows --joins the Stormcrows
[9] Targaryen --joins the Targaryens
[10] Tyrell --joins the Tyrells
+ ... omitted several edges
Let’s try to plot this.
# not sure what this does but I found it on the internet so why not :)
teams.ig <- simplify(teams.ig, remove.multiple = F, remove.loops = T)
# assign weight
E(teams.ig)$weight <- E(teams.ig)$alliance
# plot network
plot(teams.ig,
vertex.size = 10,
vertex.color = "maroon",
vertex.label.cex = .5,
main = "Game of Thrones Teams")
Warning in (function (graph, coords = NULL, dim = 2, niter = 500, start.temp =
sqrt(vcount(graph)), : NAs introduced by coercion
That looks… sort of useless (but vaguely like a network!).
---
title: "Week 1 Challenge"
author: "Claire Battaglia"
desription: "Loading data & creating a network"
date: "February 22, 2023"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
categories:
- Claire Battaglia
- challenge1
---
```{r}
#| label: setup
#| warning: false
library(tidyverse)
library(igraph)
knitr::opts_chunk$set(echo = TRUE)
```
## Data
This dataset represents the teams in Game of Thrones.
```{r data got}
# read in data
teams <- read_csv("_data/got/got_teams.csv", show_col_types = FALSE)
# specify from, to fields
teams <- teams %>%
rename(from = team, to = joins) %>%
relocate(from, to, alliance, gh, .before = id)
# preview
head(teams, 25)
```
Now I'll create a network object.
```{r network object got}
# create network object
teams.ig <- graph_from_data_frame(teams, directed = FALSE)
# view
teams.ig
```
This tells us a few things.
1. The network is *undirected*.
1. The network is *named*. I.e. the nodes have names.
1. The edges are not weighted.
1. It is not bipartite.
1. There are 66 nodes/vertices.
1. There are 33 edges/ties.
We can explore the nodes and edges further.
```{r nodes and edges got}
# get nodes
V(teams.ig)
# get edges
E(teams.ig)
```
Let's try to plot this.
```{r plot got}
# not sure what this does but I found it on the internet so why not :)
teams.ig <- simplify(teams.ig, remove.multiple = F, remove.loops = T)
# assign weight
E(teams.ig)$weight <- E(teams.ig)$alliance
# plot network
plot(teams.ig,
vertex.size = 10,
vertex.color = "maroon",
vertex.label.cex = .5,
main = "Game of Thrones Teams")
```
That looks... sort of useless (but vaguely like a network!).