-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.R
102 lines (80 loc) · 4.05 KB
/
main.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
96
97
98
99
100
101
102
# - Main analysis script -----
# Functions we're using for network analysis
source('functions.R')
# Load data ----
# Citation network. Directed.
# Format: <Citing, Cited, Number of citations>
citation.edges <- read_csv('data/processed/complete_edge_list.csv') %>%
rename(weight = Weight) %>%
filter(Source != Target) # To remove self-citations
# Remove some edges
# citation.edges <- citation.edges[-c(sample.int(50,length(citation.edges), replace=TRUE)),]
# Directed citation network ------
# Main citation network -----
cit.net <- build.network(object = citation.edges, directed = TRUE,
cluster.threshold = 0)
write.gephi(network = cit.net, network.name = "citation_complete")
write.tops(network = cit.net, network.name = "citation_complete", n.top = 10,
n.filter = 20)
write.stats(network = cit.net, network.name = "citation_complete")
write.tops(network = cit.net, network.name = "everyone", n.top = 100,
n.filter = 5)
# Snippets -----
# Get top authors and sort by degree
topAuthors <- cit.net$df %>% top_n(1000,degree) %>% arrange(desc(strength))
topAuthors
write_csv(x = topAuthors, path = paste0("results/","topAuthors", ".csv"))
# Look at distributions of authors
cit.net$df %>%
filter(community %in% c("Husserl", "James")) %>%
group_by(community) %>%
top_n(strength > 20) %>%
ggplot(aes(x = strength, y = ..density.., fill = community)) + geom_density(alpha = 0.6) + facet_grid(vars(community))
# Sub-networks (assume cit.net exists) -----
# Gets the community found using the name of any author in that community.
# Example: below "Yoshimi J" would work just as well as "Husserl E"
# Uses induced.subgraph. Looks for the community the author is in then builds a subgraph
# using only the nodes from that community and the links in it
# Husserl
husserl.net <- build.network(object = cit.net$network.object,
target.author = "Husserl E",
directed = TRUE)
write.gephi(network = husserl.net, network.name = "husserl")
write.tops(network = husserl.net, network.name = "husserl")
write.stats(network = husserl.net, network.name = "husserl")
write.tops(network = husserl.net, network.name = "husserl_all", n.top = 100,
n.filter = 5)
# Heidegger
heidegger.net <- build.network(object = cit.net$network.object,
target.author = "Heidegger M",
directed = TRUE)
write.gephi(network = heidegger.net, network.name = "heidegger")
write.tops(network = heidegger.net, network.name = "heidegger")
write.stats(network = heidegger.net, network.name = "heidegger")
write.tops(network = heidegger.net, network.name = "heidegger_all", n.top = 100,
n.filter = 5)
# Merleau-Ponty
merleauponty.net <- build.network(object = cit.net$network.object,
target.author = "Merleauponty M",
directed = TRUE)
write.gephi(network = merleauponty.net, network.name = "merleauponty")
write.tops(network = merleauponty.net, network.name = "merleauponty")
write.stats(network = merleauponty.net, network.name = "merleauponty")
write.tops(network = merleauponty.net, network.name = "mp_all", n.top = 100,
n.filter = 5)
# Cocitation networks ---------
# Co-citation networks. Undirected. How often two authors are cited together in the same document
# Format: <Cited author 1, Cited author 2, number of co-occurrences of these authors)
co.citation.edges <- read_csv('data/processed/cocitation_edge_list.csv') %>%
rename(weight = Weight) %>%
filter(Source != Target) # To remove self-citations
# Build co-citation network
coc.net <- build.network(object = co.citation.edges, directed = FALSE)
coc.net$visualization
coc.net$stats
coc.net$net.top
write.results(network = coc.net, network.name = "cocitation_complete")
# Cocitation sub-networks
merleauponty.coc.net <- analyze.network(object = coc.net$network.object, target.author = "Merleauponty M")
merleauponty.coc.net$visualization
write.results(network = merleauponty.coc.net, network.name = "cocitation_mp")