Learn R Programming

quanteda (version 0.9.8.5)

plot.dfm: plot features as a wordcloud

Description

The default plot method for a dfm object. Produces a wordcloud plot for the features of the dfm, 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.

Usage

"plot"(x, comparison = FALSE, ...)

Arguments

x
a dfm object
comparison
if TRUE, plot a comparison.cloud instead of a simple wordcloud, one grouping per document
...
additional parameters passed to to wordcloud or to text (and strheight, strwidth)

Details

The default is to plot the word cloud of all of the features in the dfm, 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. Comparison word cloud 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.

See Also

wordcloud, comparison.cloud

Examples

Run this code
# plot the features (without stopwords) from Obama's two inaugural addresses
mydfm <- dfm(subset(inaugCorpus, President=="Obama"), verbose = FALSE,
             ignoredFeatures = stopwords("english"))
plot(mydfm)

# plot in colors with some additional options passed to wordcloud
plot(mydfm, random.color = TRUE, rot.per = .25, colors = sample(colors()[2:128], 5))

## Not run: 
# # comparison plot of Irish government vs opposition
# docvars(ie2010Corpus, "govtopp") <- 
#     factor(ifelse(ie2010Corpus[, "party"] %in% c("FF", "Green"), "Govt", "Opp"))
# govtoppDfm <- dfm(ie2010Corpus, groups = "govtopp", verbose = FALSE)
# plot(tfidf(govtoppDfm), comparison = TRUE)
# # compare to non-tf-idf version
# plot(govtoppDfm, comparison = TRUE)
# ## End(Not run)

Run the code above in your browser using DataLab