I am using the following code.
library(ggplot2)
mtcars$carb <- as.factor(mtcars$carb)
mtcars$am <- as.factor(mtcars$am)
mtcars <- 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"))
This results in:
I would like to rotate the legend to obtain this desired result:
Might anyone please help? Thank you.



