Chris Bail
Duke University
website: https://www.chrisbail.net
Twitter: https://www.twitter.com/chris_bail
github: https://github.com/cbail
This package:
1) prepares texts for network analysis
2) creates text networks
3) visualizes text networks
4) detects themes or “topics” within text networks
library(devtools)
install_github("cbail/textnets")
library(textnets)
data(sotu)
sotu_first_speeches <- sotu %>%
group_by(president) %>%
slice(1L)
prepped_sotu <- PrepText(sotu_first_speeches,
groupvar = "president",
textvar = "sotu_text",
node_type = "groups",
tokenizer = "words",
pos = "nouns",
remove_stop_words = TRUE,
compound_nouns = TRUE)
sotu_text_network <- CreateTextnet(prepped_sotu)
VisTextNet(sotu_text_network, alpha=.1, label_degree_cut = 3)
library(htmlwidgets)
vis <- VisTextNetD3(sotu_text_network,
height=300,
width=400,
bound=FALSE,
zoom=FALSE,
charge=-30)
saveWidget(vis, "sotu_textnet.html")
sotu_communities <- TextCommunities(sotu_word_network)
head(sotu_communities)
top_words_modularity_classes <-
InterpretText(sotu_text_network, prepped_sotu)
head(top_words_modularity_classes, 10)
text_centrality <- TextCentrality(sotu_text_network)