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
got_edges <- read_csv(
"https://raw.githubusercontent.com/melaniewalsh/sample-social-network-datasets/master/sample-datasets/game-of-thrones/got-edges.csv",
show_col_types = FALSE
) |>
dplyr::rename(from = Source, to = Target, weight = Weight) |>
as.data.frame()
# Get nodes
got_nodes <- read_csv(
"https://raw.githubusercontent.com/melaniewalsh/sample-social-network-datasets/master/sample-datasets/game-of-thrones/got-nodes.csv",
show_col_types = FALSE
) |>
dplyr::rename(node = Id, label = Label) |>
as.data.frame()
# Create igraph object
got <- graph_from_data_frame(
got_edges, directed = FALSE, vertices = got_nodes
)
saveRDS(
got, compress = "xz", file = here("data", "got.rds")
)References
Beveridge, Andrew, and Jie Shan. 2016. “Network of Thrones.” Math Horizons 23 (4): 18–22.