21.24 Plotting Word Frequencies

We can generate the frequency count of all words in a corpus:

freq <- sort(colSums(as.matrix(dtm)), decreasing=TRUE)
head(freq, 14)
##      data      mine       use   pattern   dataset       can     model   cluster 
##      3101      1446      1366       887       776       709       703       616 
## algorithm      rule    featur       set      tree    method 
##       611       609       578       555       547       544
wf   <- data.frame(word=names(freq), freq=freq)
head(wf)
##            word freq
## data       data 3101
## mine       mine 1446
## use         use 1366
## pattern pattern  887
## dataset dataset  776
## can         can  709

We can then plot the frequency of those words that occur at least 500 times in the corpus:

subset(wf, freq>200)                                                  %>%
  ggplot(aes(word, freq))                                              +
  geom_bar(stat="identity")                                            +
  theme(axis.text.x=element_text(angle=45, hjust=1))



If you find this curated material useful then you can consider a donation to support it's ongoing availability and give you access to the PDF version of this book. The material has been scoped up by Generative AI without permission or any kind of recompense so do consider a donation if you can afford it. Unlike Generative AI your access to this materials is freely given. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Togaware has a 30 year tradition of making popular open source software which includes sold privacy preserving productivity apps, rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0