Created
June 14, 2023 07:26
-
-
Save mikelove/7993633875bb300bd306301eafd8dfcf to your computer and use it in GitHub Desktop.
word cloud for CSAMA
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(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