-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path05_arco.R
59 lines (50 loc) · 1.85 KB
/
05_arco.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
# ----- Día 5: Arco -----
# Paquetes
library(devtools)
# install_github("gastonstat/arcdiagram")
library(arcdiagram)
library(tvthemes)
library(dplyr)
# Importar fuente
#tvthemes::import_cinzel()
library(extrafont)
#font_import()
loadfonts(device = "win")
# Lectura fichero juego de tronos (temporada 1)
edges <- read.csv2("datasets/GameofThrones-T1-Network-EDGES-CSV.csv")
nodes <- read.csv2("datasets/GameofThrones-T1-Network-NODES-CSV.csv")
# Filtrado casa Lannister
nodes <- nodes %>% filter(House %in% c("\"Lannister\""))
for(i in 1:nrow(edges)){
if(!edges$Source[i] %in% nodes$Id){
edges$Source[i] <- NA
}
if(!edges$Target[i] %in% nodes$Id){
edges$Target[i] <- NA
}
}
edges <- edges %>% filter(is.na(Source) == FALSE, is.na(Target) == FALSE)
# Ordenando...
edges <- dplyr::arrange(edges, Weight)
ranking <- names(sort(table(c(edges$Source, edges$Target)), decreasing = T))
new_edges <- data.frame(Source = "", Target = "")
for(j in 1:length(ranking)){
for(i in 1:nrow(edges)){
if(edges$Source[i] == ranking[j])
new_edges <- rbind(new_edges, c(edges$Source[i], edges$Target[i]))
}
}
edges_matrix <- as.matrix(new_edges[ , 1:2])[-1, ]
edges_matrix[ , 1] <- as.numeric(edges_matrix[ , 1])
edges_matrix[ , 2] <- as.numeric(edges_matrix[ , 2])
# Para identificar el número de los nodos
arcplot(edges_matrix, show.nodes=TRUE, cex.labels = 1.5, lwd.arcs = 3)
# Para guardar el gráfico
png("5.png", units = "in", width = 10, height = 6, res = 600)
arcplot(edges_matrix, show.nodes=TRUE,
labels = c("Tywin\nLannister", "Bronn", "Tyrion\nLannister", "Cersei\nLannister",
"Lancel\nLannister", "Jaime\nLannister", "Kevan\nLannister", "Addam\nMarbrand",
"Leo\nLefford"),
cex.labels = 1.1, lwd.arcs = 3, col.nodes = "black", col.labels = "black",
col.arcs = "royalblue", family = "Cinzel")
dev.off()