library(quanteda)
library(quanteda.textplots)
corpus_subset(data_corpus_inaugural,
President %in% c("Washington", "Jefferson", "Madison")) %>%
tokens(remove_punct = TRUE) %>%
tokens_remove(stopwords("english")) %>%
dfm() %>%
dfm_group(groups = President) %>%
dfm_trim(min_termfreq = 5, verbose = FALSE) %>%
textplot_wordcloud(comparison = TRUE)
I am trying to add a title to this plot, e.g. "My First Plot". Is there a way to add a title to this plot? I can't see a method in the documentation but perhaps there is a way?
CodePudding user response:
textplot_wordcloud
uses the base R graphics engine to create the plots. This means you can use the graphics commands to adjust some of the wordcloud features.
After creating the wordcloud, you can just use title
or mtext
to add a title to your wordcloud. I used mtext
because it gives more control over where to place the text on the plot. Using title
would plot the text over "Jefferson".
corpus_subset(data_corpus_inaugural,
President %in% c("Washington", "Jefferson", "Madison")) %>%
tokens(remove_punct = TRUE) %>%
tokens_remove(stopwords("english")) %>%
dfm() %>%
dfm_group(groups = President) %>%
dfm_trim(min_termfreq = 5, verbose = FALSE) %>%
textplot_wordcloud(comparison = TRUE)
mtext("my first wordcloud",
side=3,
line=3,
at=-0.07,
adj=0,
cex=1)