ggplot2 legend items in a single horizontal row : <p>This may seem like a stupid question, but I am a little confused.</p>

<p>It seems that the code I wrote and tested last week has now suddenly decided to change the output even though nothing in the code or the version of R or Rstudio has changed.</p>

<p>Previously when I drew a plot with ggplot2 and asked for the legend to appear at the bottom of the plot, it automatically oriented the items into a single horizontal row. Now when I run the same code it places the item in a number of 2-row columns.</p>

<p>Here's an example...</p>

<pre><code>mtcars$cyl &lt;- (1:32)
subcars &lt;- subset(mtcars, cyl&lt;10)
subcars$cyl &lt;- as.factor(subcars$cyl)

ggplot(subcars, aes(carb, mpg, group=cyl, colour=cyl)) + 
  geom_line() +
  theme_classic() +
  theme(plot.title = element_text(size = rel(2), face="bold", vjust=-4)) +
  theme(legend.position = "bottom") +
  theme(legend.direction = "horizontal") +
  labs(title="Title") 
</code></pre>

<p>As you can see, I have already tried adding in the line <code>theme(legend.direction = "horizontal")</code> but I still get a legend which displays the items in 5 2-row columns (yes, its not even just in two rows).</p>

<p>Now I can only assume that there has been some update that I was not aware of or something, so I'm willing to accept that I need to come up with a new strategy for dealing with this problem (which just wasn't a problem last week). Although I am a little bit confused about why my code has suddenly decided to stop working (any input on this welcome), I'm more interested in finding a fix for the immediate problem of my legend items being displayed in a strange configuration.</p>
