Description Usage Arguments Value Examples
Get the terms weighted and scaled by tf-idf + min/max scaling associated with each of the k clusters .
1 2 3 4 5 |
x |
A |
term.cutoff |
The lowest min/max scaled tf-idf weighting to consider as a document's salient term. |
min.n |
The minimum number of terms a term must appear in a topic to be
displayed in the returned |
nrow |
The max number of rows to display in the returned
|
... |
ignored. |
Returns a list of data.frame
s of top weighted terms.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | library(dplyr)
library(textshape)
myterms <- presidential_debates_2012 %>%
with(data_store(dialogue)) %>%
hierarchical_cluster() %>%
assign_cluster(k = 55) %>%
get_terms()
myterms
textshape::bind_list(myterms[!sapply(myterms, is.null)], "Topic")
## Not run:
library(ggplot2)
library(gridExtra)
library(dplyr)
library(textshape)
library(wordcloud)
max.n <- max(textshape::bind_list(myterms)[["n"]])
myplots <- Map(function(x, y){
x %>%
mutate(term = factor(term, levels = rev(term))) %>%
ggplot(aes(term, weight=n)) +
geom_bar() +
scale_y_continuous(expand = c(0, 0),limits=c(0, max.n)) +
ggtitle(sprintf("Topic: %s", y)) +
coord_flip()
}, myterms, names(myterms))
myplots[["ncol"]] <- 10
do.call(gridExtra::grid.arrange, myplots[!sapply(myplots, is.null)])
##wordclouds
par(mfrow=c(5, 11), mar=c(0, 4, 0, 0))
Map(function(x, y){
wordcloud::wordcloud(x[[1]], x[[2]], scale=c(1,.25),min.freq=1)
mtext(sprintf("Topic: %s", y), col = "blue", cex=.55, padj = 1.5)
}, myterms, names(myterms))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.