ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

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

Open Breeze-Hu opened this issue 7 months ago • 6 comments

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

Breeze-Hu avatar Mar 19 '25 08:03 Breeze-Hu