I'd like a ggplot2
legend to feature keys of a constant width, no matter the size of the associated label.
For instance
library(plyr)
library(tidyverse)
mtcars %>%
group_by(cyl, gear) %>%
tally %>%
mutate(
gear = gear %>%
plyr::mapvalues(
3:5,
c(
"3 g short",
"4 gears medium",
"Five gears long label"
)
)
) %>%
ggplot(
aes(factor(cyl), n, fill = gear)
) +
geom_col(
color = "grey10",
size = .1
) +
scale_fill_grey(
guide = guide_legend(label.position = "bottom")
) +
theme_minimal() +
theme(
legend.position = "bottom"
)
returns
The three shades of grey fill are shown as having different widths, as a function of the label length. How might I ensure that the fill key entries are all the same size?