A simple word cloud
At this point, you have had too much coffee. Plus, seeing the top words such as "shop", "morning", and "drinking" among others just isn't all that insightful.
In celebration of making it this far, let's try our hand on another batch of 1000 tweets. For now, you won't know what they have in common, but let's see if you can figure it out using a word cloud. The tweets' term frequency values are preloaded in your workspace.
A word cloud is a visualization of terms. In a word cloud, size is often scaled to frequency, and in some cases, the colors may indicate another measurement. For now, we're keeping it simple: size is related to individual word frequency, and we are just selecting a single color.
As you saw in the video, the wordcloud()
function works like this:
wordcloud(words, frequencies, max.words = 500, colors = "blue")
Text mining analyses often include simple word clouds. In fact, they are probably overused, but can still be useful for quickly understanding a body of text!
term_frequency
is loaded into your workspace.
Cet exercice fait partie du cours
Text Mining with Bag-of-Words in R
Instructions
- Load the
wordcloud
package. - Print out first 10 entries in
term_frequency
. - Extract the terms using
names()
onterm_frequency
. Call the vector of stringsterms_vec
. - Create a
wordcloud()
usingterms_vec
as the words, andterm_frequency
as the values. Add the parametersmax.words = 50
andcolors = "red"
.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Load wordcloud package
# Print the first 10 entries in term_frequency
# Vector of terms
# Create a word cloud for the values in word_freqs