Skip to content

Legend size adjustment within guides #6339

Closed
@Breeze-Hu

Description

@Breeze-Hu

Hi!

When I tried to adjust the legend.key.size in guides it doesn't seem to work as expected. But legend.key.spacing.y works fine.
When I include it in the theme(adjusting the whole legend?) , the code works very well.

I'm not sure if this is similar to the question below? Or is it a bug? If this behavior is indeed due to an underlying mechanism, wouldn’t it be preferable for the documentation to include a note about it, as is done for this issue?
#6263

Here is the code to reproduce the issue:

library(tidyverse)

data = tibble(x = rep(c('a','b'),each = 10),
              y = runif(20,min = 0, max=10))

ggplot(data = data, aes(x = x, y = y, fill = x))+
  geom_boxplot()+
  guides(fill = guide_legend(theme = theme(legend.key.spacing.y = unit(5,'lines'),
                                           legend.key.size = unit(3, 'lines')))
         )

Image

ggplot(data = data, aes(x = x, y = y, fill = x))+
  geom_boxplot()+
  guides(fill = guide_legend(theme = theme(legend.key.spacing.y = unit(5,'lines')))
  )+
  theme(legend.key.size = unit(3, 'lines'))

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions