Created
March 9, 2018 14:05
-
-
Save sfirke/e3f0c27bd05c67c3caa21b09900b3b31 to your computer and use it in GitHub Desktop.
Make wordclouds from a text column in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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