<div>We all have words we love to use, and that we perhaps use too much. As an example: I have a tendency to use the same transitional statements, to the point that, before I submit a manuscript, I do a find all to see how many times I’ve used some of my favorites, e.g., additionally, though, and so on.
<p>I’m sure we all have our own words we use way too often.</p>
<div><iframe width="450" allowfullscreen src="https://www.youtube.com/embed/KrJYpActs7g"></iframe></div>
<p>Text analysis can also be used to discover patterns in writing, and for a writer, may be helpful in discovering when we depend too much on certain words and phrases. For today’s demonstration, I read in my (still in-progress) novel – a murder mystery called <i>Killing Mr. Johnson</i> – and did the same type of text analysis I’ve been demonstrating in recent posts.</p>
<p>To make things easier, I copied the document into a text file, and used the read_lines and tibble functions to prepare data for my analysis.</p>
<div>
<div>
<div>
<pre><span>setwd</span><span>(</span><span>&quot;~/Dropbox/Writing/Killing Mr. Johnson&quot;</span><span>)</span><br><br><span>library</span><span>(tidyverse)</span><br></pre>
</div>
<div>
<pre><span>KMJ_text</span> <span>&lt;-</span> <span>read_lines</span><span>(</span><span>'KMJ_full.txt'</span><span>)</span><br><br><span>KMJ</span> <span>&lt;-</span> <span>tibble</span><span>(KMJ_text)</span> <span>%>%</span><br>  <span>mutate</span><span>(</span><span>linenumber</span> <span>=</span> <span>row_number</span><span>())</span><br></pre>
</div>
</div>
</div>
<p>I kept my line numbers, which I could use in some future analysis. For now, I’m going to tokenize my data, drop stop words, and examine my most frequently used words.</p>
<div>
<div>
<div>
<pre><span>library</span><span>(tidytext)</span><br><span>KMJ_words</span> <span>&lt;-</span> <span>KMJ</span> <span>%>%</span><br>  <span>unnest_tokens</span><span>(word, KMJ_text)</span> <span>%>%</span><br>  <span>anti_join</span><span>(stop_words)</span><br></pre>
</div>
<div>
<pre>## Joining, by = &quot;word&quot;<br></pre>
</div>
<div>
<pre><span>KMJ_words</span> <span>%>%</span><br>  <span>count</span><span>(word,</span> <span>sort</span> <span>=</span> <span>TRUE</span><span>)</span> <span>%>%</span><br>  <span>filter</span><span>(n</span> <span>></span> <span>75</span><span>)</span> <span>%>%</span><br>  <span>mutate</span><span>(</span><span>word</span> <span>=</span> <span>reorder</span><span>(word, n))</span> <span>%>%</span><br>  <span>ggplot</span><span>(</span><span>aes</span><span>(word, n))</span> <span>+</span><br>  <span>geom_col</span><span>()</span> <span>+</span> <span>xlab</span><span>(</span><span>NULL</span><span>)</span> <span>+</span> <span>coord_flip</span><span>()</span><br></pre>
</div>
</div>
<p></p>
<div><a rel="nofollow" href="https://i2.wp.com/4.bp.blogspot.com/-GjsxpFsisa0/W3nyypJA0vI/AAAAAAAANco/2z0pPhkqfeszs8EwOeHFrlwPoHg6cCfzQCLcBGAs/s1600/words.png?ssl=1" target="_blank"><img border="0" src="https://i0.wp.com/4.bp.blogspot.com/-GjsxpFsisa0/W3nyypJA0vI/AAAAAAAANco/2z0pPhkqfeszs8EwOeHFrlwPoHg6cCfzQCLcBGAs/s320/words.png?resize=320%2C242&ssl=1" data-original-width="450" width="320" data-original-height="483" data-recalc-dims="1" height="242"></a></div>
</div>
<p>Fortunately, my top 5 words are the names of the 5 main characters, with the star character at number 1: Emily is named almost 600 times in the book. It’s a murder mystery, so I’m not too surprised that words like “body” and “death” are also common. But I know that, in my fiction writing, I often depend on a word type that draws a lot of disdain from authors I admire: adverbs. Not all adverbs, mind you, but specifically (pun intended) the “-ly adverbs.”</p>
<div>
<div>
<div>
<pre><span>ly_words</span> <span>&lt;-</span> <span>KMJ_words</span> <span>%>%</span><br>  <span>filter</span><span>(</span><span>str_detect</span><span>(word,</span> <span>&quot;.ly&quot;</span><span>))</span> <span>%>%</span><br>  <span>count</span><span>(word,</span> <span>sort</span> <span>=</span> <span>TRUE</span><span>)</span><br><br><span>head</span><span>(ly_words)</span><br></pre>
</div>
<div>
<pre>## # A tibble: 6 x 2<br>##   word         n<br>##   </pre></div></div></div></div>