# NOT RUN {
# 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"))
# for keyness
tstat <- tail(data_corpus_inaugural, 2) %>%
dfm(remove_punct = TRUE, remove = stopwords("en")) %>%
textstat_keyness(target = 2)
textplot_wordcloud(tstat, max_words = 100)
textplot_wordcloud(tstat, comparison = FALSE, max_words = 100)
# }
Run the code above in your browser using DataLab