-
Notifications
You must be signed in to change notification settings - Fork 1
/
03_one_mode_networks.r
95 lines (74 loc) · 2.99 KB
/
03_one_mode_networks.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
library(tidyverse)
library(igraph)
library(ggraph)
library(graphlayouts)
p <- readr::read_tsv("data/participants.tsv", col_types = "cccc") %>%
select(i, j, role)
# load only organisers, chairs/discussants and participants to 'ST' panels
d <- readr::read_tsv("data/edges.tsv", col_types = "icciiiiccc") %>%
left_join(p, by = c("i", "j")) %>% # add roles
filter(str_detect(j, "_ST(.*)"), role %in% c("c", "d", "o", "p"))
# l <- c("Participant(e) mono-panel", "Participant(e) multi-panels")
l <- c("Mono-panel participant", "Multi-panel participant")
for (y in unique(d$year)) {
e <- filter(d, year == y)
# make sure all panels have 1+ organiser(s) and 2+ participants
w <- group_by(e, j) %>%
summarise(n_o = sum(role == "o"), n_p = sum(role != "o")) %>%
filter(n_p < 3 | n_o < 1 | n_o == n_p)
# [TOFIX] fix [2019] data in order for this test to pass!
# stopifnot(!nrow(w))
e <- purrr::map_df(unique(e$j), function(p) {
tidyr::expand_grid( # actually twice slower than `expand.grid`...
i = e$i[ e$role == "o" & e$j == p ],
j = e$i[ e$role != "o" & e$j == p ] # "c", "d", "p"
) %>%
tibble::add_column(p)
}) %>%
group_by(p) %>%
mutate(weight = 1 / n_distinct(j)) # inverse weighting re: panel size
# expected left skew in edge weights
# hist(e$weight)
n <- igraph::graph_from_data_frame(e) # carries `p` and `weight` on edges
E(n)$weight <- E(n)$weight / max(E(n)$weight)
V(n)$size <- igraph::degree(n)
# tibble::tibble(name = V(n)$name, degree = V(n)$size) %>%
# arrange(-degree) %>%
# print()
e <- filter(d, year == y) %>%
group_by(i) %>%
summarise(n_p = n_distinct(j))
w <- e$n_p
names(w) <- e$i
V(n)$color <- as.integer(w[ V(n)$name ])
V(n)$color <- if_else(V(n)$color == 1, "P1", "P2+")
cat("\nYear", y, ":", igraph::components(n)$no, "components\n")
print(table(V(n)$color))
ggraph(n, layout = "stress", bbox = 20) +
geom_edge_link(aes(alpha = weight), show.legend = FALSE) +
geom_node_point(aes(size = size, color = color), alpha = 2/3) +
scale_color_manual("", values = c("P1" = "steelblue3", "P2+" = "tomato3"), labels = l) +
guides(size = FALSE) +
theme_graph(base_family = "Helvetica", base_size = 14) +
theme(
legend.text = element_text(size = rel(1)),
legend.position = "bottom",
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5)
) +
labs(
# title = str_c("Congrès AFSP ", y),
title = str_c("AFSP Meeting ", y),
# subtitle = str_c(
# sum(V(n)$color == "P1"), " participant(e)s, ",
# sum(V(n)$color == "P2+"), " dans plusieurs panels"
# )
subtitle = str_c(
sum(V(n)$color == "P1"), " participants, ",
sum(V(n)$color == "P2+"), " in multiple panels"
)
)
ggsave(str_c("plots/congres-afsp", y, "-1mode.pdf"), width = 8, height = 9)
ggsave(str_c("plots/congres-afsp", y, "-1mode.png"), width = 8, height = 9, dpi = 150)
}
# kthxbye