title: Rotate boxplot legend (R, ggplot2)
body: <p>I am using the following code.</p>
  
  <pre><code> library(ggplot2)
   mtcars$carb &lt;- as.factor(mtcars$carb)
   mtcars$am &lt;- as.factor(mtcars$am)
   mtcars &lt;- mtcars[!(mtcars$carb==6 | mtcars$carb==8),]
   ggplot(mtcars) + 
      geom_boxplot(aes(x = carb, y = mpg, fill = am), 
                   position = position_dodge(0.9)) +
   guides(fill = guide_legend(direction = "horizontal"))
  </code></pre>
  
  <p>This results in:</p>
  
  <p><a href="https://i.stack.imgur.com/zgScQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zgScQ.png" alt="enter image description here"></a></p>
  
  <p>I would like to rotate the legend to obtain this desired result:</p>
  
  <p><a href="https://i.stack.imgur.com/dh2cd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dh2cd.png" alt="enter image description here"></a></p>
  
  <p>Might anyone please help? Thank you.</p>