Create a lexical dispersion plot based on the sentiment word results

First you need set your working directory (for me, that is setwd(“~/git-space/hacking-moby-dick/”)).

Then you load two libraries:

library(“rJava”)

library(“qdap”)

Next you will load the text.

md.text <- scan("moby-dick.txt", what = "characters", sep = "\n")

Now we just run a dispersion_plot function that finds select terms and places them in relation to each other in the space of the text. You can type in whichever terms you would like to map by changing them in the “c” (combine) function.

dispersion_plot(md.text, c("poor", "strange", "dead", "death", "wild", "dark", "whale", "ahab", "great", "well", "good", "right", "best", "work"),
                color = "black", bg.color = "grey90", horiz.color = "grey85",
                total.color = "black", symbol = "|", title = "Lexical Dispersion Plot in Moby-Dick",
                rev.factor = TRUE, wrap = "'", xlab = NULL, ylab = "Word Frequencies",
                size = 3, plot = TRUE)

What kinds of questions can you generate from the placement of these words?

Now try to change the search terms.

Return to Week 8.