tidyverse / tidyverse/ggplot2

legend.key.spacing change the distance between the key and the label

Open
#6,366 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation guides :straight_ruler:
Dominant language
R
Stars
7k
Forks
2.1k
Avg merge
59m
Merged PRs (30d)
2

Description

Hi!
Currently ggplot provides identity-detailed options for adjusting the properties of each element of the legend. The following options for legend.key.spacing{x/y}, which adjusts the distance of each mini group, and legend.text both work as expected.
ggplot2 3.5.0: Legends - Spacing and margins

(p <- ggplot(mpg, aes(displ, hwy, colour = class)) +
  geom_point() +
  guides(colour = guide_legend(ncol = 2)) 
)

p+  
  theme(
    legend.key.spacing.x = unit(20, "pt"))
Image

But I have a doubt about the legend.key.spacing:

p+
  theme(legend.key.spacing = unit(20, "pt"))
Image

From the result, it looks like the key and label spacing has changed. As legend.text = element_text (margin = margin (l = ...)) has been changed.

Should the distance between key and label change when using legend.key.spacing? I'm not quite sure if this is an intentional feature or a bug.

Best wishes,
Hu

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the two examples from the issue, using the linked ggplot2 3.5.0 spacing documentation as context. Trace the legend layout and theme handling that determine the distance between keys and labels. Done means establishing whether legend.key.spacing is intended to affect that distance and, if it is a bug, adding a focused regression test and correcting the documented behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.