title: Legend on bottom, two rows wrapped in ggplot2 in r
body: <pre><code>library(ggplot2)
  library(scales)
  library(reshape2)  
  
  Rdates &lt;- c(&quot;2007-01-31&quot;,&quot;2007-02-28&quot;,&quot;2007-03-30&quot;,&quot;2007-04-30&quot;,&quot;2007-05-31&quot;,&quot;2007-06-29&quot;,&quot;2007-07-31&quot;,&quot;2007-08-31&quot;,&quot;2007-09-28&quot;,&quot;2007-10-31&quot;)
  Rdates &lt;- as.Date(Rdates)
  Cnames &lt;- c(&quot;Column 1 Really Long&quot;,&quot;Column 2 Really Long&quot;,&quot;Column 3 Really Long&quot;,&quot;Column 4 Really Long&quot;,&quot;Column 5 Really Long&quot;,&quot;Column 6 Really Long&quot;,&quot;Column 7 Really Long&quot;,&quot;Column 8 Really Long&quot;,&quot;Column 9 Really Long&quot;,&quot;Column 10 Really Long&quot;)
  MAINDF &lt;- data.frame(replicate(10,runif(10,-0.03,0.03)))
  rownames(MAINDF) &lt;- Rdates
  colnames(MAINDF) &lt;- Cnames
  CUSTOMpalette &lt;- c(&quot;#1a2ffa&quot;, &quot;#0d177d&quot;, &quot;#1a9ffa&quot;, &quot;#fa751a&quot;, &quot;#4b8e12&quot;, &quot;#6fd21b&quot;, &quot;#fae51a&quot;, &quot;#c3b104&quot;, &quot;#f5df05&quot;, &quot;#dcc805&quot;)
  MAINDF[,&quot;dates&quot;] &lt;- Rdates
  
  MAINDF &lt;- melt(MAINDF,id.vars=&quot;dates&quot;)
  
  gg &lt;- ggplot(MAINDF, aes(x = dates, y = value, fill = variable))
  gg &lt;- gg + geom_bar(stat = &quot;identity&quot;)
  gg &lt;- gg + scale_x_date(breaks = &quot;3 months&quot;, labels=date_format(&quot;%b%y&quot;),limits=c(min(as.Date(MAINDF$dates)),max(as.Date(MAINDF$dates))))
  gg &lt;- gg + theme(
    axis.text.x= element_text(color=&quot;black&quot;,angle=45, size=10, vjust=0.5),
    axis.text.y= element_text(color=&quot;black&quot;, size=12, vjust=0.5),
    axis.title.y = element_text(color=&quot;black&quot;,size=12, vjust=0.5),
    plot.title = element_text(color=&quot;black&quot;,face=&quot;bold&quot;,size=14, hjust=0.5,vjust=1),
    panel.background = element_blank(),
    panel.border = element_rect(linetype = &quot;solid&quot;, colour = &quot;black&quot;,fill=NA),
    legend.position=&quot;bottom&quot;,
    legend.title = element_blank(),
    legend.key = element_rect(fill=&quot;white&quot;), legend.background = element_rect(fill=NA)
  )
  gg &lt;- gg + xlab(&quot;&quot;) + ylab(&quot;Monthly Returns&quot;) 
  gg &lt;- gg + ggtitle(&quot;Contribution by Strategy&quot;)
  gg &lt;- gg + scale_y_continuous(labels = percent_format())
  gg &lt;- gg + scale_fill_manual(values=CUSTOMpalette)
  gg
  </code></pre>
  <p>Currently have a ggplot2 stacked bar graph setup. Everything works properly now except I am having an issue with the legend. I have put it on the bottom but there are 10 items so some are cutoff (doesnt fit). I tried  <code>guides(fill=guide_legend(nrow=2))</code> but this puts the labels in a different order (I want to get the first 5 across then the last 5 below. Any suggestions?</p>