-
-
Save tonmcg/052abe086e06568a9659766793ddc797 to your computer and use it in GitHub Desktop.
Make wordclouds from a text column in R
This file contains 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