[DEMO]
Netword data can be thought of as two related tables, nodes and edges:
## # A tibble: 45 x 2## label Gender## <fct> <fct> ## 1 Betty Draper female## 2 Don Draper male ## 3 Harry Crane male ## 4 Joan Holloway female## 5 Lane Pryce male ## 6 Peggy Olson female## 7 Pete Campbell male ## 8 Roger Sterling male ## 9 Sal Romano male ## 10 Henry Francis male ## # … with 35 more rows
## # A tibble: 39 x 2## Name1 Name2 ## <fct> <fct> ## 1 Betty Draper Henry Francis ## 2 Betty Draper Random guy ## 3 Don Draper Allison ## 4 Don Draper Bethany Van Nuys## 5 Don Draper Betty Draper ## 6 Don Draper Bobbie Barrett ## 7 Don Draper Candace ## 8 Don Draper Doris ## 9 Don Draper Faye Miller ## 10 Don Draper Joy ## # … with 29 more rows
One way to describe these relationships is to provide association matrix between many objects.
(Image created by Sam Tyner.)
tidygraph
and ggraph
library(tidygraph)library(ggraph)madmen_graph <- tbl_graph( nodes = madmen$vertices, edges = madmen$edges, directed = FALSE )
## # A tbl_graph: 45 nodes and 39 edges## ### # An undirected simple graph with 6 components## ### # Node Data: 45 x 2 (active)## label Gender## <fct> <fct> ## 1 Betty Draper female## 2 Don Draper male ## 3 Harry Crane male ## 4 Joan Holloway female## 5 Lane Pryce male ## 6 Peggy Olson female## # … with 39 more rows## ### # Edge Data: 39 x 2## from to## <int> <int>## 1 1 2## 2 1 3## 3 4 5## # … with 36 more rows
gg_madmen <- ggraph(madmen_graph, layout = "kk") + geom_edge_link() + geom_node_label(aes(colour = Gender, label = label))
gg_madmen
madmen_graph %>% activate(nodes) %>% mutate(count = centrality_degree()) %>% arrange(-count) %>% as_tibble()
## # A tibble: 45 x 3## label Gender count## <fct> <fct> <dbl>## 1 Joan Holloway female 14## 2 Woman at the Clios party female 6## 3 Janine female 5## 4 Duck Phillips male 4## 5 Betty Draper female 3## 6 Rachel Menken female 3## 7 Hildy female 3## 8 Joy female 2## 9 Vicky female 2## 10 Don Draper male 1## # … with 35 more rows
activate()
what now?madmen_graph
## # A tbl_graph: 45 nodes and 39 edges## ### # An undirected simple graph with 6 components## ### # Node Data: 45 x 2 (active)## label Gender## <fct> <fct> ## 1 Betty Draper female## 2 Don Draper male ## 3 Harry Crane male ## 4 Joan Holloway female## 5 Lane Pryce male ## 6 Peggy Olson female## # … with 39 more rows## ### # Edge Data: 39 x 2## from to## <int> <int>## 1 1 2## 2 1 3## 3 4 5## # … with 36 more rows
nodes
or edges
. activate
means we don't need a mutate_nodes
or mutate_edges
commandscentrality
what now?madmen_graph %>% activate(nodes) %>% mutate(count = centrality_degree()) %>% arrange(-count) %>% as_tibble()
## # A tibble: 45 x 3## label Gender count## <fct> <fct> <dbl>## 1 Joan Holloway female 14## 2 Woman at the Clios party female 6## 3 Janine female 5## 4 Duck Phillips male 4## 5 Betty Draper female 3## 6 Rachel Menken female 3## 7 Hildy female 3## 8 Joy female 2## 9 Vicky female 2## 10 Don Draper male 1## # … with 35 more rows
centrality_degree()
says: "What is the number of adjacent edges?"Early American football outfits were like Australian AFL today!
Source: wikicommons
Fall 2000 Season of Division I college football.
foot_graph
## # A tbl_graph: 115 nodes and 613 edges## ### # A directed acyclic simple graph with 1 component## ### # Node Data: 115 x 3 (active)## uni conference schools## <chr> <chr> <chr> ## 1 BrighamYoung Mountain West <NA> ## 2 FloridaState Atlantic Coast <NA> ## 3 Iowa Big Ten <NA> ## 4 KansasState Big Twelve <NA> ## 5 NewMexico Mountain West <NA> ## 6 TexasTech Big Twelve <NA> ## # … with 109 more rows## ### # Edge Data: 613 x 3## from to same.conf## <int> <int> <dbl>## 1 1 2 0## 2 3 4 0## 3 1 5 1## # … with 610 more rows
set.seed(2019-09-25-1117)gg_foot_graph <-ggraph(foot_graph, layout = "fr") + geom_edge_link(alpha = 0.2) + geom_node_point(size = 7, alpha = 0.9, aes(colour = conference)) + scale_colour_brewer(palette = "Paired") + theme(legend.position = "bottom")
There is a connection between two students if one provides emotional support to the other at some point in the book.
hp
## # A tbl_graph: 64 nodes and 434 edges## ### # A directed multigraph with 29 components## ### # Node Data: 64 x 4 (active)## name schoolyear gender house ## <chr> <dbl> <chr> <chr> ## 1 Adrian Pucey 1989 M Slytherin ## 2 Alicia Spinnet 1989 F Gryffindor## 3 Angelina Johnson 1989 F Gryffindor## 4 Anthony Goldstein 1991 M Ravenclaw ## 5 Blaise Zabini 1991 M Slytherin ## 6 C. Warrington 1989 M Slytherin ## # … with 58 more rows## ### # Edge Data: 434 x 3## from to book## <int> <int> <dbl>## 1 11 25 1## 2 11 26 1## 3 11 44 1## # … with 431 more rows
ggraph_hp <- ggraph(hp, layout = "fr") + geom_edge_link(alpha = 0.2) + geom_node_point(aes(colour = house, shape = gender)) + # geom_node_text(aes(label = name)) + facet_edges(~book, ncol = 2) + scale_colour_manual(values = c("#941B08","#F1F31C", "#071A80", "#154C07"))
ggraph_hp
s1_name
and s2_name
are the first names of class members, and tutors, with the latter being the "go-to" person for the former.
This work is licensed under a Creative Commons Attribution 4.0 International License.
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |