-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathigraph_plotting.R
More file actions
50 lines (40 loc) · 1.61 KB
/
igraph_plotting.R
File metadata and controls
50 lines (40 loc) · 1.61 KB
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
library(igraph)
library(tidygraph)
source("./functions.R")
graph <- readRDS(gzcon(url("https://github.com/schnee/tangled/blob/master/data/graph.RDS?raw=true")))
edge_pal <- c("#C0C0C0", "#FFA500", "#00B300", "#FF0000")
node_pal <- get_palette(graph)
the_edge_types <- graph %>% activate(edges) %>%
pull(d_type) %>% factor() %>% levels()
the_clusters <- graph %>% activate(nodes) %>%
pull(group) %>%
factor() %>%
levels()
the_cluster_lab <- graph %>% activate(nodes) %>%
pull(group_label) %>% factor() %>% levels()
g <- graph %>% activate(edges) %>%
mutate(color = edge_pal[match(d_type, the_edge_types)],
arrow.size = 1,
width = 5) %>%
activate(nodes) %>%
mutate(color = node_pal[match(group_label, the_cluster_lab)],
alpha_hex = if_else(n_tri > 0, "aa", "88"),
label.color = if_else(n_tri > 0, "#000000FF", "#00000022"),
color = paste0(color, alpha_hex),
size = 3,
frame.color = "NA",
label.cex = 2) %>%
weight_graph(1, 0.4)
title_txt <- paste0(graph %>% activate(nodes) %>%
as_tibble %>% arrange(desc(centrality)) %>%
pull(name) %>% first(),"'s Tangled Web")
png(filename = "tangled-base.png", width = 4000, height = 3000)
par(ps = 12, cex = 1, cex.main = 8)
plot(g, layout = layout_with_drl, options = igraph::drl_defaults$final)
title(title_txt, line = -3)
legend("topright", legend = the_edge_types,
col = edge_pal, lty = 1, cex = 4,
lwd = 8, title = "Relationship")
legend("bottomright", legend = the_cluster_lab, fill = node_pal, cex =4,
title = "Group")
dev.off()