set.seed(123)
# Required packages
library(here)
library(tidyverse)
library(igraph)
Appendix: Data acquisition
Here, I will describe how I obtained each example data set used in this course.
got.rds
This file contains an igraph
object with a network consisting of character relationships in George R. R. Martin’s A Storm of Swords, the third novel in his series A Song of Ice and Fire. Data were originally compiled by Beveridge and Shan (2016).
# Get edges
<- read_csv(
got_edges "https://raw.githubusercontent.com/melaniewalsh/sample-social-network-datasets/master/sample-datasets/game-of-thrones/got-edges.csv",
show_col_types = FALSE
|>
) ::rename(from = Source, to = Target, weight = Weight) |>
dplyras.data.frame()
# Get nodes
<- read_csv(
got_nodes "https://raw.githubusercontent.com/melaniewalsh/sample-social-network-datasets/master/sample-datasets/game-of-thrones/got-nodes.csv",
show_col_types = FALSE
|>
) ::rename(node = Id, label = Label) |>
dplyras.data.frame()
# Create igraph object
<- graph_from_data_frame(
got directed = FALSE, vertices = got_nodes
got_edges,
)
saveRDS(
compress = "xz", file = here("data", "got.rds")
got, )
References
Beveridge, Andrew, and Jie Shan. 2016. “Network of Thrones.” Math Horizons 23 (4): 18–22.