Wordcloud of the Arizona et al. v. United States opinion

[This article was first published on Bommarito Consulting » r, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Here’s one purely for fun – a wordcloud built from the Supreme Court’s opinion on Arizona et al. v United States.  Word clouds, though certainly not the most scientific of visualization techniques, are often engaging and “fun” ways to lead into discussion on NLP or topic modeling.

Arizona  et al. v United States wordcloud

Arizona et al. v United States wordcloud

The process to generate this image is entirely automated with Tika and R.  We convert the PDF to text, strip, normalize, and stopword the text, then convert to histogram and plot as a wordcloud. Here’s the snippet below:

$ java -jar /opt/tika/tika.jar --text arizona_et_al_v_united_states.pdf >  arizona_et_al_v_united_states.txt
$ R
>  library(tm)
>  library(wordcloud)
>  library(RColorBrewer)
>  corpus <- Corpus(DirSource(pattern="*.txt"))
>  corpus <- tm_map(tm_map(tm_map(corpus, removePunctuation), tolower), function(x) removeWords(x, stopwords("english")))
>  tdMatrix <- as.matrix(TermDocumentMatrix(corpus))
>  tdMatrix <- sort(rowSums(tdMatrix), decreasing=T)
>  freqDF <- data.frame(words=names(tdMatrix), freq=tdMatrix)
>  colorPalette <- brewer.pal(8, "RdBu")
>  png(file="arizona_v_usa_wordcloud.png", bg="black")
>  wordcloud(freqDF$words, freqDF$freq, scale=c(8, 0.25), min.freq=10, random.order=F, rot.per=0.2, colors=colorPalette)
>  dev.off()

To leave a comment for the author, please follow the link and comment on their blog: Bommarito Consulting » r.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)