#' @name makePaperCloud
#' @title Paper Cloud Maker
#' @description Make word cloud of papers
#' @param tab Table generated by googleCite
#' @param addstopwords words to remove
#' @param ... Not currently used.
#' @return NULL (Plot rendered)
#' @export
makePaperCloud <- function(tab, addstopwords=NULL, ...) {
colIndex = which(names(tab) == "Title")
corpus <- Corpus(DataframeSource(data.frame(tab[, colIndex])))
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, content_transformer(tolower))
corpus <- tm_map(corpus, function(x) removeWords(x, stopwords("english")))
if (!is.null(addstopwords)) corpus <- tm_map(corpus, function(x)
removeWords(x, addstopwords))
tdm <- TermDocumentMatrix(corpus)
m <- as.matrix(tdm)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
pal = brewer.pal(9, "RdPu")
pal <- pal[-(1:4)]
wordcloud(words = d$word, freq = d$freq,
min.freq = 1, max.words = Inf,
random.order = FALSE, colors = pal,vfont=c("sans serif","plain"))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.