Text Networks

Chris Bail
Duke University

What is a Network?

What is a Network?

Two-Mode Networks

For a technical overview, see Bail (2016) or Rule et al (2015)

State of the Union Addresses

State of the Union Addresses

Textnets

Textnets

This package:

1) prepares texts for network analysis
2) creates text networks
3) visualizes text networks
4) detects themes or “topics” within text networks

Textnets

library(devtools)

install_github("cbail/textnets")

Example: State of the Union Addresses

library(textnets)

data(sotu)

Part of Speech Tagging Takes Time...

sotu_first_speeches <- sotu %>% 
                        group_by(president) %>% 
                          slice(1L)

PrepText w/Nouns

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)

Creating Textnets w/Nouns

sotu_text_network <- CreateTextnet(prepped_sotu)

Visualize Textnet w/Nouns

VisTextNet(sotu_text_network, alpha=.1, label_degree_cut = 3)

Visualize Textnet w/Nouns

Interactive Visualization

library(htmlwidgets)
vis <- VisTextNetD3(sotu_text_network, 
                      height=300,
                      width=400,
                      bound=FALSE,
                      zoom=FALSE,
                      charge=-30)
saveWidget(vis, "sotu_textnet.html")

Word-Based Projection

Analyzing Text Networks

sotu_communities <- TextCommunities(sotu_word_network)

head(sotu_communities)

Analyzing Text Networks

top_words_modularity_classes <- 
      InterpretText(sotu_text_network, prepped_sotu)

head(top_words_modularity_classes, 10)

Centrality Measures

text_centrality <- TextCentrality(sotu_text_network)

Next Steps with Textnets