library(ggplot2) ggplot(mtcars, aes(factor(cyl), fill = factor(cyl))) + geom_bar() + coord_flip() + scale_fill_brewer("Cyl", palette = "Dark2") + theme_minimal(base_size = 14) + theme(legend.position = 'top', legend.spacing.x = unit(1.0, 'cm'))