Chapter 4 First Graphs
4.1 Les Miserable Dataset
# Load igraph
library(igraph)
# Read data
lesmis <- read.csv("https://raw.githubusercontent.com/meefen/sna-ed/master/assets/lesmis/lesmis.csv")
# check the head (first 6 rows) of the dataset
head(lesmis)
## Source Target weight
## 1 1 0 1
## 2 2 0 8
## 3 3 0 10
## 4 3 2 6
## 5 4 0 1
## 6 5 0 1
4.2 Stop light
library(sigmajs)
library(tibble)
edges <- tibble(id = rep("1", 3),
source = rep("1", 3),
target = as.character(c(2:4))
)
nodes <- tibble(id = as.character(1:4),
label = c("light", "red", "yellow", "green"),
time = c(100, 30, 10, 20)
)
sigmajs() %>%
sg_nodes(nodes, id, label, time) %>%
sg_edges(edges, id, source, target)