New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

legend titles need more padding #1881

baptiste opened this Issue Oct 29, 2016 · 2 comments


None yet
2 participants

baptiste commented Oct 29, 2016

Not sure if it's a recent change (I'm using the dev version fresh from github), but with a large enough font the legend title collides with the legend and I can't find any setting to move it.


dummy <- data.frame(x=runif(10), y=runif(10), f = gl(2,5))
ggplot(dummy, aes(x,y, shape=f)) + 
  geom_point() +
  labs(shape="guide") +

With the default font size things are OK, albeit snug

screen shot 2016-10-29 at 4 58 42 pm

With a larger font size (graphic aimed for slides), however,

screen shot 2016-10-29 at 4 58 34 pm

I tried,

legend.margin = margin(100,100,100,100)
legend.spacing.y = unit(1,"cm")
legend.title = element_text(vjust = 2)

also played with guide_legend etc. to no avail.

@baptiste baptiste closed this Oct 29, 2016


This comment has been minimized.


baptiste commented Oct 29, 2016

the relevant part seems to be in guide-legend.r

First, the text height is not accurately measured,

g <- ggplot2:::element_grob(
  element_text(angle = 0),
  label = "guide",
  hjust =  0.5,
  vjust =  0.5,
  expand_x = FALSE,
  expand_y = FALSE

grid.rect(height=unit(ggplot2:::height_cm(g), "cm"),gp=gpar(fill=NA))

(it seems to be a limitation in grid, descenders aren't included for some reason). Not much to do about it. In passing height_cm should probably use grobHeight, not grobWidth.

screen shot 2016-10-29 at 5 19 04 pm

And second there isn't any setting to change the margin, vgap is hard-coded to 0.3 lines


This comment has been minimized.


baptiste commented Oct 29, 2016

oh, and I just had a quick look at guide-colorbar.r, it's the same problem, but the corresponding lines of code are slightly different, probably written by someone else.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.