Visualize word networks
Another way to view word connections is to treat them as a network, similar to a social network. Word networks show term association and cohesion. A word of caution: these visuals can become very dense and hard to interpret visually.
In a network graph, the circles are called nodes and represent individual terms, while the lines connecting the circles are called edges and represent the connections between the terms.
For the over-caffeinated text miner, qdap provides a shortcut for making word networks. The word_network_plot() and word_associate() functions both make word networks easy!
The sample code constructs a word network for words associated with "Marvin".
This exercise is part of the course
Text Mining with Bag-of-Words in R
Exercise instructions
Update the word_associate() plotting code to work with the coffee data.
- Change the vector to
coffee_tweets$text. - Change the match string to
"barista". - Change
"chardonnay"to"coffee"in the stopwords too. - Change the title to
"Barista Coffee Tweet Associations"in the sample code for the plot.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Word association
word_associate(chardonnay_tweets$text, match.string = "marvin",
stopwords = c(Top200Words, "chardonnay", "amp"),
network.plot = TRUE, cloud.colors = c("gray85", "darkred"))
# Add title
title(main = "Chardonnay Tweets Associated with Marvin")