Wrap legend text containing expression
<p>I have been looking for a wrapper function in ggplot2 which can help me put the legend text in a defined rectangular area.</p>

<p>So far I haven't found one. Here is my case:</p>

<pre><code>library (ggplot2)
p = ggplot (mtcars, aes (x = mpg, y= cyl,color = factor (cyl)))
p + geom_point()
z = unique (factor (mtcars$cyl))
p + geom_point() + scale_color_manual(name="legend title", breaks = z, 
                                  labels = c (expression(a + b + c + d + e + f + g + h + i), expression(x) ,  expression(y ) ),
                                  values = c("red","blue","green") )
</code></pre>

<p>What I want is to have the long expression wrapped within a width of <strong>five characters</strong>.</p>

<p>Is there any function which can automatically wrap each legend key's text in a defined text width, and I am wondering if that can also be applicable for expressions.</p>