Jasmin Shah Jasmin Shah - 1 month ago 15
R Question

How to add more words into wordcloud R package that can be excluded in the output?

I'm using package "wordcloud" with description "Word Cloud" from the R Packages repository. When I create wordcloud from some random text, some words are omitted automatically as they should not be a part of wordcloud. Now, I want to add more words like "this" and "that" to the package so they get excluded from wordcloud as well.

Currently, these words are being excluded from text: "is, to, be, I, not, a, of, out, but, who, here, how, in, some, so, that, it, because, against, Oh, by"

Answer

If you don't have to many words to be removed, you can do

set.seed(1)
library(wordcloud)
stopwords <- c("my", "foo", "buzz")
txt <- "hello world. hello my world again. Foo bar fizz buzz."
clean <- gsub(paste(stopwords, collapse="|"), "", txt, ignore.case = TRUE)
par(mfrow = c(1,2))
wordcloud(txt)
wordcloud(clean)

enter image description here

Comments