Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make wordclouds from a text column in R
library(pacman)
p_load(tidytext, wordcloud, janeaustenr, dplyr)
data("stop_words")
ppdf <- data.frame(prideprejudice, stringsAsFactors = FALSE)
# create a word cloud
create_word_cloud <- function(dat, col_name, exclude = "", max.words = 50, colors = "#034772", ...){
col <- deparse(substitute(col_name))
dat %>%
select_(col) %>%
unnest_tokens_("word", col) %>%
filter(! word %in% exclude) %>%
count(word) %>%
with(wordcloud(word, n, max.words = max.words, colors = colors, ...))
}
create_word_cloud(ppdf, prideprejudice, exclude = stop_words$word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment