Skip to content

Remove space for legend title if it doesn't have a title #3587

@steveharoz

Description

@steveharoz

If a guide has a label, you can make it flush with the edge of a plot:

ggplot(PlantGrowth) + 
  aes(x=group, y=weight, fill=group) +
  geom_boxplot() + 
  theme(
    legend.position="top", 
    legend.justification = "left", 
    legend.margin = margin(0, 0, 0, 0))

image

But if you set the label to NULL, a there is a gap or misalignment that doesn't seem to be removable:

ggplot(PlantGrowth) + 
  aes(x=group, y=weight, fill=group) +
  geom_boxplot() + 
  labs(fill = NULL) + # removes legend title
  theme(
    legend.position="top", 
    legend.justification = "left", 
    legend.margin = margin(0, 0, 0, 0))

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