r:social_network_analysis_tutorial
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
r:social_network_analysis_tutorial [2019/11/27 08:13] – [Using ifelse] hkimscil | r:social_network_analysis_tutorial [2023/11/23 08:50] (current) – hkimscil | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== T1. ====== | ====== T1. ====== | ||
+ | '' | ||
+ | see [[https:// | ||
===== Dataset ===== | ===== Dataset ===== | ||
<file csv star-wars-network-edges.csv> | <file csv star-wars-network-edges.csv> | ||
Line 657: | Line 659: | ||
</ | </ | ||
+ | < | ||
+ | par(mar=c(0, | ||
+ | plot(g) | ||
+ | </ | ||
+ | {{: | ||
+ | |||
+ | ===== %in% ===== | ||
+ | |||
+ | < | ||
+ | # what does %in% do? | ||
+ | 1 %in% c(1,2,3,4) | ||
+ | 1 %in% c(2,3,4) | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | > 1 %in% c(1,2,3,4) | ||
+ | [1] TRUE | ||
+ | > 1 %in% c(2,3,4) | ||
+ | [1] FALSE | ||
+ | > | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | dark_side <- c(" | ||
+ | light_side <- c(" | ||
+ | " | ||
+ | "GOLD LEADER", | ||
+ | other <- c(" | ||
+ | # node we'll create a new color variable as a node property | ||
+ | V(g)$color <- NA # V(g)에 color라는 컬럼을 만든다 | ||
+ | V(g)$color[V(g)$name %in% dark_side] <- " | ||
+ | # V(g)$name이 dark_side에 있는 이름이면 color 컬럼에 " | ||
+ | V(g)$color[V(g)$name %in% light_side] <- " | ||
+ | V(g)$color[V(g)$name %in% other] <- " | ||
+ | vertex_attr(g) | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | par(mar=c(0, | ||
+ | plot(g) | ||
+ | legend(x=.75, | ||
+ | | ||
+ | </ | ||
+ | {{: | ||
+ | |||
+ | ===== Edges ===== | ||
+ | < | ||
+ | E(g)$width <- log(E(g)$weight) + 1.5 # create width column in the graph, g | ||
+ | edge_attr(g) | ||
+ | </ | ||
+ | < | ||
+ | > E(g)$width <- log(E(g)$weight) + 1.5 # create width column in the graph, g | ||
+ | > edge_attr(g) | ||
+ | $weight | ||
+ | [1] 17 13 6 5 5 3 1 7 5 16 19 11 1 1 2 2 | ||
+ | [17] 4 1 3 3 2 3 18 2 6 17 1 19 6 1 2 1 | ||
+ | [33] 7 9 26 1 1 6 1 1 13 1 1 1 1 1 1 2 | ||
+ | [49] 1 1 3 3 1 1 3 1 2 1 1 1 | ||
+ | |||
+ | $width | ||
+ | [1] 4.333213 4.064949 3.291759 3.109438 3.109438 | ||
+ | [6] 2.598612 1.500000 3.445910 3.109438 4.272589 | ||
+ | [11] 4.444439 3.897895 1.500000 1.500000 2.193147 | ||
+ | [16] 2.193147 2.886294 1.500000 2.598612 2.598612 | ||
+ | [21] 2.193147 2.598612 4.390372 2.193147 3.291759 | ||
+ | [26] 4.333213 1.500000 4.444439 3.291759 1.500000 | ||
+ | [31] 2.193147 1.500000 3.445910 3.697225 4.758097 | ||
+ | [36] 1.500000 1.500000 3.291759 1.500000 1.500000 | ||
+ | [41] 4.064949 1.500000 1.500000 1.500000 1.500000 | ||
+ | [46] 1.500000 1.500000 2.193147 1.500000 1.500000 | ||
+ | [51] 2.598612 2.598612 1.500000 1.500000 2.598612 | ||
+ | [56] 1.500000 2.193147 1.500000 1.500000 1.500000 | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | par(mar=c(0, | ||
+ | plot(g) | ||
+ | </ | ||
+ | {{: | ||
+ | |||
+ | < | ||
+ | par(mfrow=c(2, | ||
+ | plot(g, layout=layout_randomly, | ||
+ | plot(g, layout=layout_in_circle, | ||
+ | plot(g, layout=layout_as_star, | ||
+ | plot(g, layout=layout_as_tree, | ||
+ | plot(g, layout=layout_on_grid, | ||
+ | plot(g, layout=layout_with_fr, | ||
+ | par(mfrow=c(1, | ||
+ | </ | ||
+ | {{: | ||
+ | |||
+ | cf. layout_with_fr: | ||
+ | < | ||
+ | par(mfrow=c(1, | ||
+ | set.seed(777) | ||
+ | fr <- layout_with_fr(g, | ||
+ | par(mar=c(0, | ||
+ | set.seed(666) | ||
+ | fr <- layout_with_fr(g, | ||
+ | par(mar=c(0, | ||
+ | |||
+ | </ | ||
+ | {{: | ||
+ | |||
+ | |||
+ | ===== Measurements ===== | ||
+ | < | ||
+ | degree(g, mode = " | ||
+ | closeness(g, | ||
+ | betweenness(g, | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | > degree(g, mode = " | ||
+ | R2-D2 | ||
+ | 7 | ||
+ | | ||
+ | | ||
+ | | ||
+ | 1 | ||
+ | GOLD FIVE | ||
+ | 0 | ||
+ | > closeness(g, | ||
+ | R2-D2 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | GOLD FIVE | ||
+ | | ||
+ | Warning message: | ||
+ | In closeness(g, | ||
+ | At centrality.c: | ||
+ | > betweenness(g, | ||
+ | R2-D2 | ||
+ | 0.011904762 0.035487528 0.057596372 0.297278912 0.011904762 0.000000000 0.032142857 | ||
+ | | ||
+ | 0.217120181 0.005442177 0.000000000 0.014852608 0.000000000 0.000000000 0.176190476 | ||
+ | | ||
+ | 0.000000000 0.000000000 0.011111111 0.003174603 0.003174603 0.032142857 0.000000000 | ||
+ | GOLD FIVE | ||
+ | 0.000000000 | ||
+ | > | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | g.c.deg <- degree(g, mode = " | ||
+ | g.c.clo <- closeness(g, | ||
+ | g.c.bet <- betweenness(g, | ||
+ | tmp <- data.frame(g.c.deg, | ||
+ | tmp[order(-g.c.clo, | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | > g.c.deg <- degree(g, mode = " | ||
+ | > g.c.clo <- closeness(g, | ||
+ | Warning message: | ||
+ | In closeness(g, | ||
+ | At centrality.c: | ||
+ | > g.c.bet <- betweenness(g, | ||
+ | > tmp <- data.frame(g.c.deg, | ||
+ | > | ||
+ | > tmp | ||
+ | g.c.deg | ||
+ | R2-D2 7 0.38181818 0.011904762 | ||
+ | CHEWBACCA | ||
+ | C-3PO 10 0.40384615 0.057596372 | ||
+ | LUKE 15 0.44680851 0.297278912 | ||
+ | DARTH VADER 5 0.32812500 0.011904762 | ||
+ | CAMIE 2 0.32307692 0.000000000 | ||
+ | BIGGS 7 0.36842105 0.032142857 | ||
+ | LEIA 12 0.42000000 0.217120181 | ||
+ | BERU 4 0.35000000 0.005442177 | ||
+ | OWEN 3 0.32812500 0.000000000 | ||
+ | OBI-WAN | ||
+ | MOTTI 3 0.31343284 0.000000000 | ||
+ | TARKIN | ||
+ | HAN 8 0.38888889 0.176190476 | ||
+ | GREEDO | ||
+ | JABBA 1 0.28767123 0.000000000 | ||
+ | DODONNA | ||
+ | GOLD LEADER | ||
+ | WEDGE 5 0.33870968 0.003174603 | ||
+ | RED LEADER | ||
+ | RED TEN 2 0.32307692 0.000000000 | ||
+ | GOLD FIVE 0 0.04545455 0.000000000 | ||
+ | > | ||
+ | > tmp[order(-g.c.clo, | ||
+ | g.c.deg | ||
+ | LUKE 15 0.44680851 0.297278912 | ||
+ | LEIA 12 0.42000000 0.217120181 | ||
+ | C-3PO 10 0.40384615 0.057596372 | ||
+ | HAN 8 0.38888889 0.176190476 | ||
+ | CHEWBACCA | ||
+ | OBI-WAN | ||
+ | R2-D2 7 0.38181818 0.011904762 | ||
+ | BIGGS 7 0.36842105 0.032142857 | ||
+ | RED LEADER | ||
+ | BERU 4 0.35000000 0.005442177 | ||
+ | DODONNA | ||
+ | GOLD LEADER | ||
+ | WEDGE 5 0.33870968 0.003174603 | ||
+ | DARTH VADER 5 0.32812500 0.011904762 | ||
+ | OWEN 3 0.32812500 0.000000000 | ||
+ | CAMIE 2 0.32307692 0.000000000 | ||
+ | RED TEN 2 0.32307692 0.000000000 | ||
+ | MOTTI 3 0.31343284 0.000000000 | ||
+ | TARKIN | ||
+ | GREEDO | ||
+ | JABBA 1 0.28767123 0.000000000 | ||
+ | GOLD FIVE 0 0.04545455 0.000000000 | ||
+ | > | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | g.c.bac <- distances(g, | ||
+ | g.c.bac | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | > g.c.bac <- distances(g, | ||
+ | > g.c.bac | ||
+ | R2-D2 CHEWBACCA C-3PO LUKE DARTH VADER CAMIE BIGGS LEIA BERU OWEN OBI-WAN MOTTI | ||
+ | R2-D2 | ||
+ | TARKIN HAN GREEDO JABBA DODONNA GOLD LEADER WEDGE RED LEADER RED TEN GOLD FIVE | ||
+ | R2-D2 2 | ||
+ | </ | ||
r/social_network_analysis_tutorial.1574809992.txt.gz · Last modified: 2019/11/27 08:13 by hkimscil