title: R: Wrap a long text so that each line has the same length
body: <p>I am trying to add a long text to a plot. The goal is to wrap the text so that each line is equal in length. I looked through several functions: <code>strwrap</code>, <code>format</code>, <code>text</code>. But none of these seem to have an option for making the lines equal.</p>
  
  <p>I imagine the solution should adding spaces between words in shorter lines to make up for missing characters. Maybe there is a function/argument that I missed?</p>
  
  <p>Below is my current wrapping (without equal lengths):</p>
  
  <pre><code>txt &lt;- paste(sample(LETTERS, 1000, replace=TRUE), collapse="")
  txt &lt;- strsplit(txt, "A|I|O|E|U")
  txt &lt;- paste(txt[[1]], collapse=" ")
  
  plot(NA, xlim=c(0,1), ylim=c(0,1))
  text(0.0, 0.5, paste(strwrap(txt, width=50), collapse="\n"), pos=4, cex=0.7)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/81OUK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/81OUK.png" alt="textplot"></a></p>