Skip to content
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

Closed
baptiste opened this issue Oct 29, 2016 · 2 comments
Closed

legend titles need more padding #1881

baptiste opened this issue Oct 29, 2016 · 2 comments
Labels
feature a feature request or enhancement themes 💃

Comments

@baptiste
Copy link
Contributor

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.

MRE

set.seed(123)
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") +
  theme_grey(24)

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
Copy link
Contributor Author

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.newpage()
grid.draw(g)
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

@baptiste
Copy link
Contributor Author

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.

@hadley hadley added feature a feature request or enhancement themes 💃 labels Jan 25, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement themes 💃
Projects
None yet
Development

No branches or pull requests

2 participants