Skip to content

Instantly share code, notes, and snippets.

@mikelove
Created June 14, 2023 07:26
Show Gist options
  • Save mikelove/7993633875bb300bd306301eafd8dfcf to your computer and use it in GitHub Desktop.
Save mikelove/7993633875bb300bd306301eafd8dfcf to your computer and use it in GitHub Desktop.
word cloud for CSAMA
library(tm)
library(wordcloud)
crude <- scan("words", what="char", sep="\n")
crude <- gsub("/"," ",crude)
crude <- gsub("single cell","singlecell",crude)
crude <- Corpus(VectorSource(crude))
crude <- suppressWarnings(tm_map(crude, removePunctuation))
crude <- suppressWarnings(tm_map(crude, function(x) removeWords(x, stopwords())))
tdm <- TermDocumentMatrix(crude)
m <- as.matrix(tdm)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word=names(v),freq=v,row.names=NULL)
pal <- brewer.pal(12,"Paired")[-11]
wordcloud(d$word, d$freq, scale=c(2.5,.1),
min.freq=1, random.color=TRUE, colors=pal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment