Description
In the current stable version, legend.key.height
and legend.key.width
work as expected:
packageVersion("ggplot2")
# '3.5.2'
library(ggplot2)
p <- ggplot(mpg) +
geom_point(aes(x = factor(cyl), y = displ, color = hwy)) +
scale_color_fermenter(palette = "RdYlBu", direction = 1) +
theme(legend.key.width = unit(0.25, "lines"))
plots <- list(
p + ggtitle("default"),
p + ggtitle("0.5 lines") + theme(legend.key.height = unit(0.5, "lines")),
p + ggtitle("2.5 lines") + theme(legend.key.height = unit(2.5, "lines")),
p + ggtitle("null") + theme(legend.key.height = unit(1, "null"))
)
cowplot::plot_grid(plotlist = plots)
But in the dev version, legend.key.height
has no effect:
# in fresh session
remotes::install_github("tidyverse/ggplot2")
packageVersion("ggplot2")
# '3.5.2.9000'
library(ggplot2)
# same plotting code as above
If theme(legend.direction = "horizontal")
, then legend.key.height
works OK but legend.key.width
doesn't.
The same issue seems to affect continuous scales. Discrete scales seem to work OK but I didn't investigate extensively.