title: Wrap long axis labels via labeller=label_wrap in ggplot2
body: <p>I would like to automatically wrap my labels in ggplot2, i.e. insert line breaks of long labels. <a href="https://github.com/hadley/ggplot2/wiki/labeller" rel="noreferrer">Here</a> is written how to write a function (1) for it, but sadly I do not know where to put <code>labeller=label_wrap</code> in my code (2).</p>
  <p>(1) function by hadley</p>
  <pre><code>label_wrap &lt;- function(variable, value) {
    lapply(strwrap(as.character(value), width=25, simplify=FALSE), 
           paste, collapse=&quot;\n&quot;)
  }
  </code></pre>
  <p>(2) code example</p>
  <pre><code>df = data.frame(x = c(&quot;label&quot;, &quot;long label&quot;, &quot;very, very long label&quot;), 
                  y = c(10, 15, 20))
  
  ggplot(df, aes(x, y)) + geom_bar(stat=&quot;identity&quot;)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/BBPRW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/BBPRW.png" alt="Histogram with long label not wrapped" /></a></p>
  <p>I'd like to wrap some of the longer labels here.</p>