Skip to content

Instantly share code, notes, and snippets.

@zkamvar
Last active January 5, 2024 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkamvar/dfe58b0410e6158ec7a0758647ebf700 to your computer and use it in GitHub Desktop.
Save zkamvar/dfe58b0410e6158ec7a0758647ebf700 to your computer and use it in GitHub Desktop.
Generate a wordcloud from my dissertation
library('rjson')
library('wordcloud')
library('viridis')
library('magrittr')
library('purrr')
library('svglite')
# Download JSON data ------------------------------------------------------
diss <- "https://raw.githubusercontent.com/zkamvar/dissertation/master/docs/search_index.json"
dissertation <- readLines(diss) %>%
paste(collapse = " ") %>%
fromJSON()
# Set up the plot ---------------------------------------------------------
the_colors <- viridis::viridis(30, begin = 0.25, option = "B")
svglite::svglite("dissertation.svg", width = 7, height = 7, bg = "black")
# Extract text, filter, and create the word cloud -------------------------
set.seed(20161206) # Set the seed for my defense date ^_^
purrr::map_chr(dissertation[-7], 3) %>% # Extracting text of all chapters (not bib)
gsub("\\(.+?\\)\\.", ".", .) %>% # Removing most citations
wordcloud::wordcloud(colors = the_colors, scale = c(3, 0.25), rot.per = 0.2,
random.order = FALSE)
dev.off()
@zkamvar
Copy link
Author

zkamvar commented Dec 31, 2016

PNG output:

dissertation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment