title: Quanteda: How do I create a corpus and plot dispersion of words?
body: <p>I have some data which looks like this:</p>
  <pre class="lang-r prettyprint-override"><code>  date      signs  horoscope                                                      newspaper   
    &lt;chr&gt;     &lt;chr&gt;  &lt;chr&gt;                                                          &lt;chr&gt;       
  1 06-06-20~ ARIES  Your week falls neatly into distinct phases. The completion o~ Indian Expr~
  2 06-06-20~ TAURUS You're coming to the end of an emotional period, when you've ~ Indian Expr~
  3 06-06-20~ GEMINI Passions are still running high, and the degree of emotional ~ Times of In~
  4 06-06-20~ CANCER First things first - don't rush it! There is still a great de~ Indian Expr~
  5 06-06-20~ LEO    The greatest pressures are coming from all directions at once~ Indian Expr~
  </code></pre>
  <p>I would like to create a corpus out of this data where all <code>horoscope</code> are grouped together by <code>newspaper</code> and <code>signs</code> as documents.</p>
  <p>For example, all <code>ARIES</code> in the newspaper <code>Times of India</code> should be one document, but arranged chronologically in order of date (their index should be ordered by date).</p>
  <p>Since I don't know how to group this text by <code>newspaper</code> and <code>signs</code>, I tried creating two different corpuses for each newspaper. I have tried doing this:</p>
  <pre class="lang-r prettyprint-override"><code>
  # Create a dataframe of only Times of India text
  h_toi &lt;- horoscopes %&gt;%
    filter(newspaper == &quot;Times of India&quot;) %&gt;%
    select(-c(&quot;newspaper&quot;))
    
  # Create a corpus of out this
  horo_corp_toi &lt;- corpus(h_toi, text_field = &quot;horoscope&quot;)
  
  # Create docids
  docids &lt;- paste(h_toi$signs)
  
  # Use this as docnames
  docnames(horo_corp_toi) &lt;- docids
  
  head(docnames(horo_corp_toi), 5)
  # [1] &quot;ARIES.1&quot;  &quot;TAURUS.1&quot; &quot;GEMINI.1&quot; &quot;CANCER.1&quot; &quot;LEO.1&quot; 
  </code></pre>
  <p>But as you can see, the <code>docnames</code> for the corpus are <code>&quot;ARIES.1&quot;</code>,  `&quot;TAURUS.1&quot; and so on. This is a problem since when I try to plot it using quanteda's <a href="https://quanteda.io/articles/pkgdown/examples/plotting.html" rel="nofollow noreferrer">textplot_xray()</a>, there are thousands of documents plotted instead of just 12 documents for each sign:</p>
  <pre class="lang-r prettyprint-override"><code># Plot lexical dispersion of love in all signs 
  kwic(tokens(horo_corp_toi), pattern = &quot;love&quot;) %&gt;%
      textplot_xray()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ObMle.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ObMle.png" alt="enter image description here" /></a></p>
  <p>Instead, I would like to be able to do something like this:
  <a href="https://i.stack.imgur.com/zcH7M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zcH7M.png" alt="enter image description here" /></a></p>
  <p>I am not able to get this visualization because I don't know how to manipulate and create the corpus initially. How can I do this, and what am I doing wrong?</p>
  <p>Sample DPUT is <a href="https://pastebin.com/LYaxJstk" rel="nofollow noreferrer">here</a></p>