Created
May 18, 2019 20:27
-
-
Save juliasilge/b2fd4bf16e414c8d48ca8eece7e8f3e8 to your computer and use it in GitHub Desktop.
Word co-occurrence network graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidytext) | |
library(widyr) | |
library(igraph) | |
library(ggraph) | |
words_cooccur <- tidy_words %>% | |
group_by(word) %>% | |
filter(n() > 250) %>% | |
ungroup() %>% | |
pairwise_cor(word, Respondent, sort = TRUE, upper = FALSE) %>% | |
filter(correlation > 0.11) | |
word_counts <- tidy_words %>% | |
count(word, sort = TRUE) %>% | |
filter(word %in% words_cooccur$item1 | word %in% words_cooccur$item2) | |
words_cooccur %>% | |
graph_from_data_frame(vertices = word_counts) %>% | |
ggraph(layout = "nicely") + | |
geom_edge_link(aes(edge_alpha = correlation), | |
edge_width = 0.5, show.legend = FALSE) + | |
geom_node_point(aes(size = n), | |
alpha = 0.7) + | |
geom_node_text(aes(label = name), repel = TRUE) + | |
labs(size = "Number of\nuses") + | |
theme_void() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment