textplot_wordcloud.Rd
Plot a dfm object as a wordcloud, where the feature labels are plotted
with their sizes proportional to their numerical values in the dfm. When
comparison = TRUE
, it plots comparison word clouds by document.
textplot_wordcloud(x, min_size = 0.5, max_size = 4, min_count = 3, max_words = 500, color = "darkblue", font = NULL, adjust = 0, rotation = 0.1, random_order = FALSE, random_color = FALSE, ordered_color = FALSE, labelcolor = "gray20", labelsize = 1.5, labeloffset = 0, fixed_aspect = TRUE, ..., comparison = FALSE)
x | a dfm object |
---|---|
min_size | size of the smallest word |
max_size | size of the largest word |
min_count | words with frequency below min_count will not be plotted |
max_words | maximum number of words to be plotted. least frequent terms dropped. |
color | color of words from least to most frequent |
font | font-family of words and labels. Use default font if |
adjust | adjust sizes of words by a constant. Useful for non-English words for which R fails to obtain correct sizes. |
rotation | proportion of words with 90 degree rotation |
random_order | plot words in random order. If |
random_color | choose colors randomly from the colors. If |
ordered_color | if |
labelcolor | color of group labels. Only used when |
labelsize | size of group labels. Only used when |
labeloffset | position of group labels. Only used when
|
fixed_aspect | if |
... | additional parameters. Only used to make it compatible with wordcloud |
comparison | if |
The default is to plot the word cloud of all features, summed across documents. To produce word cloud plots for specific document or set of documents, you need to slice out the document(s) from the dfm object.
Comparison wordcloud plots may be plotted by setting comparison =
TRUE
, which plots a separate grouping for each document in the dfm.
This means that you will need to slice out just a few documents from the
dfm, or to create a dfm where the "documents" represent a subset or a
grouping of documents by some document variable.
# plot the features (without stopwords) from Obama's inaugural addresses set.seed(10) dfmat1 <- dfm(corpus_subset(data_corpus_inaugural, President == "Obama"), remove = stopwords("english"), remove_punct = TRUE) %>% dfm_trim(min_termfreq = 3) # basic wordcloud textplot_wordcloud(dfmat1)# plot in colors with some additional options textplot_wordcloud(dfmat1, rotation = 0.25, color = rev(RColorBrewer::brewer.pal(10, "RdBu")))# other display options col <- sapply(seq(0.1, 1, 0.1), function(x) adjustcolor("#1F78B4", x)) textplot_wordcloud(dfmat1, adjust = 0.5, random_order = FALSE, color = col, rotation = FALSE)# comparison plot of Obama v. Trump dfmat2 <- dfm(corpus_subset(data_corpus_inaugural, President %in% c("Obama", "Trump")), remove = stopwords("english"), remove_punct = TRUE, groups = "President") %>% dfm_trim(min_termfreq = 3) textplot_wordcloud(dfmat2, comparison = TRUE, max_words = 300, color = c("blue", "red"))#> Warning: national could not be fit on page. It will not be plotted.#> Warning: victories could not be fit on page. It will not be plotted.#> Warning: every could not be fit on page. It will not be plotted.#> Warning: americans could not be fit on page. It will not be plotted.#> Warning: land could not be fit on page. It will not be plotted.#> Warning: action could not be fit on page. It will not be plotted.#> Warning: longer could not be fit on page. It will not be plotted.#> Warning: success could not be fit on page. It will not be plotted.#> Warning: nations could not be fit on page. It will not be plotted.#> Warning: pledge could not be fit on page. It will not be plotted.#> Warning: brave could not be fit on page. It will not be plotted.#> Warning: created could not be fit on page. It will not be plotted.#> Warning: knowing could not be fit on page. It will not be plotted.#> Warning: require could not be fit on page. It will not be plotted.#> Warning: together could not be fit on page. It will not be plotted.#> Warning: workers could not be fit on page. It will not be plotted.#> Warning: always could not be fit on page. It will not be plotted.#> Warning: strength could not be fit on page. It will not be plotted.#> Warning: made could not be fit on page. It will not be plotted.#> Warning: meaning could not be fit on page. It will not be plotted.#> Warning: nation could not be fit on page. It will not be plotted.#> Warning: forward could not be fit on page. It will not be plotted.#> Warning: prosperity could not be fit on page. It will not be plotted.#> Warning: schools could not be fit on page. It will not be plotted.#> Warning: america's could not be fit on page. It will not be plotted.#> Warning: come could not be fit on page. It will not be plotted.#> Warning: understand could not be fit on page. It will not be plotted.#> Warning: blood could not be fit on page. It will not be plotted.#> Warning: government could not be fit on page. It will not be plotted.#> Warning: today could not be fit on page. It will not be plotted.#> Warning: throughout could not be fit on page. It will not be plotted.#> Warning: gather could not be fit on page. It will not be plotted.#> Warning: politics could not be fit on page. It will not be plotted.#> Warning: interests could not be fit on page. It will not be plotted.#> Warning: roads could not be fit on page. It will not be plotted.#> Warning: restore could not be fit on page. It will not be plotted.#> Warning: harness could not be fit on page. It will not be plotted.#> Warning: alliances could not be fit on page. It will not be plotted.#> Warning: protect could not be fit on page. It will not be plotted.#> Warning: celebration could not be fit on page. It will not be plotted.#> Warning: patriots could not be fit on page. It will not be plotted.#> Warning: shores could not be fit on page. It will not be plotted.#> Warning: justice could not be fit on page. It will not be plotted.#> Warning: today's could not be fit on page. It will not be plotted.#> Warning: middle could not be fit on page. It will not be plotted.#> Warning: pride could not be fit on page. It will not be plotted.#> Warning: poverty could not be fit on page. It will not be plotted.#> Warning: forever could not be fit on page. It will not be plotted.#> Warning: hear could not be fit on page. It will not be plotted.#> Warning: different could not be fit on page. It will not be plotted.#> Warning: women could not be fit on page. It will not be plotted.#> Warning: moment could not be fit on page. It will not be plotted.#> Warning: children could not be fit on page. It will not be plotted.#> Warning: challenges could not be fit on page. It will not be plotted.#> Warning: demands could not be fit on page. It will not be plotted.#> Warning: remember could not be fit on page. It will not be plotted.#> Warning: knowledge could not be fit on page. It will not be plotted.