Last active
January 5, 2024 16:26
-
-
Save zkamvar/dfe58b0410e6158ec7a0758647ebf700 to your computer and use it in GitHub Desktop.
Generate a wordcloud from my dissertation
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('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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PNG output: