pacman::p_load(jsonlite, tidygraph, ggraph, visNetwork, tidyverse)In-class Exercise 5
VAST Challenge - MC1
Installing R Packages
jsonlitepackage is needed to read json files
visNetworkfor visualising networks
Loading the json Data
MC1 <- jsonlite::fromJSON("data/MC1.json")glimpse(MC1)List of 5
$ directed : logi TRUE
$ multigraph: logi TRUE
$ graph : Named list()
$ nodes :'data.frame': 3428 obs. of 4 variables:
..$ type : chr [1:3428] "company" "organization" "organization" "organization" ...
..$ dataset: chr [1:3428] "MC1" "MC1" "MC1" "MC1" ...
..$ country: chr [1:3428] "Nalakond" NA NA NA ...
..$ id : chr [1:3428] "Spanish Shrimp Carriers" "12744" "143129355" "7775" ...
$ links :'data.frame': 11069 obs. of 6 variables:
..$ type : chr [1:11069] "ownership" "partnership" "partnership" "ownership" ...
..$ weight : num [1:11069] 0.9 0.846 0.965 0.964 0.823 ...
..$ dataset: chr [1:11069] "MC1" "MC1" "MC1" "MC1" ...
..$ source : chr [1:11069] "Spanish Shrimp Carriers" "Spanish Shrimp Carriers" "Spanish Shrimp Carriers" "Spanish Shrimp Carriers" ...
..$ target : chr [1:11069] "12744" "21323516" "290834957" "3506021" ...
..$ key : int [1:11069] 0 0 0 0 0 0 0 0 0 0 ...
Create separate tibbles for nodes and edges
MC1_nodes <- as_tibble(MC1$nodes) %>%
# Select can be used to reorder dataframe columns
select(id, type, country)
MC1_edges <- as_tibble(MC1$links) %>%
# Move Source and Target to the front
select(source, target, type, weight, key)