I'm creating a plot visualising proportions of an ordered categorical variable with approximately 30 levels. The legend is displayed at the bottom of the plot. I'd like to control the number of rows the legend spans - i.e., be able to control how many horizontal lines the legend categories are plotted over, to make it appear as wide as the main plot.
I'd like to control the number of lines they span, so I can make the legend as wide as the main plot (which would probably be two lines or so here). The default settings puts them on 7 rows, using legend.direction = "horizontal" in theme() doesn't solve it, and I have'nt been able to find another setting that works.
A working, simplified reprex is inserted below. Any help would be appreciated. Thanks in advance!
library(ggplot2) df <- data.frame(a = 1, val = factor(sample(0:30, 1000, TRUE))) ggplot(df, aes(y = a, fill = val)) + geom_bar(position = "fill") + theme(legend.position = "bottom")