R :: tm - Create a table/matrix of term association frequencies and add values to dendrogram
<p>I got a corpus that basically a vector of short sentences (n > 50), e.g.:</p>

<pre><code>corpus &lt;- c("looking for help in R","check whether my milk is sour or not",
"random sentence with dubious meaning")
</code></pre>

<p>I am able to print a dendrogram</p>

<pre><code>fit &lt;- hclust(d, method="ward")   
plot(fit, hang=-1)
groups &lt;- cutree(fit, k=nc)   # "k=" defines the number of clusters you are using   
rect.hclust(fit, k=nc, border="red") # draw dendrogram with red borders around the 5 clusters 
</code></pre>

<p>and a correlation matrix</p>

<pre><code>cor_1 &lt;- cor(as.matrix(dtms))
corrplot(cor_1, method = "number")
</code></pre>

<p><a href="https://i.stack.imgur.com/4VMo2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4VMo2.png" alt=""></a></p>

<p>As far as I have understood it - please correct me here if I am wrong - <code>findAssocs()</code> i.e. correlation checks whether two terms appear in the same document?</p>

<p><strong>Goal:</strong>
Now I don't want to see the correlation, but the frequency of two terms appear in the same document which are NOT necessarily adjacent to each other (BigramTokenizer won't work). For example: term A and term B appear together in 5 different documents across my corpus regardless of distance.</p>

<p>Ideally I want to create a frequency matrix similar to the one above and add the frequencies to the dendrogram if possible (akin to where <code>pvclust()</code> prints their numbers)</p>

<p><a href="https://i.stack.imgur.com/oaMvE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oaMvE.png" alt="enter image description here"></a></p>

<p>Any ideas on how to achieve this?</p>