-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Vertical space between legend keys changed after switching theme? #3180
Comments
each theme defines/redefines various properties. You can see the defaults here Possibly the reason for what you see is here:
and redefined by
That, I'm guessing, explains the extra white color between legend keys. To test that, use P.S. I haven't looked at the source code, but setting |
It's down to the difference between library(reprex)
library(ggplot2)
theme_set(theme_bw(base_size = 14))
theme_update(legend.key = element_rect(size = 6, fill = "white", colour = NA), legend.key.size = unit(1, "cm"))
ggplot(mtcars) +
aes(fill = factor(cyl), x = cyl) +
geom_bar() Created on 2019-03-15 by the reprex package (v0.2.1) library(reprex)
library(ggplot2)
theme_set(theme_bw(base_size = 14))
theme_update(legend.key = element_rect(size = 6, fill = "white", colour = "white"), legend.key.size = unit(1, "cm"))
ggplot(mtcars) +
aes(fill = factor(cyl), x = cyl) +
geom_bar() Created on 2019-03-15 by the reprex package (v0.2.1) |
Setting the color to black makes it clearer what happens. The spacing doesn't change, but there's an additional border that is drawn and that covers some of the key parts. Maybe we should remove this border for library(ggplot2)
theme_set(theme_bw(base_size = 14))
theme_update(legend.key = element_rect(size = 6, fill = "white", colour = "black"), legend.key.size = unit(1, "cm"))
ggplot(mtcars) +
aes(fill = factor(cyl), x = cyl) +
geom_bar() Created on 2019-03-15 by the reprex package (v0.2.1) |
Thanks @ptoche & @clauswilke ! That makes sense. So is there a way to make the size of those legend boxes the same? The blue key box is noticeably larger than the others. |
I would recommend to just set library(ggplot2)
theme_set(theme_bw(base_size = 14))
theme_update(legend.key = element_rect(size = 6, fill = "white", colour = NA), legend.key.size = unit(1, "cm"))
ggplot(mtcars) +
aes(fill = factor(cyl), x = cyl) +
geom_bar() Created on 2019-03-15 by the reprex package (v0.2.1) |
Thanks @clauswilke ! Now I understand. Would be great if this is fixed int the future release |
Sorry, I'm confused... Are you talking about library(ggplot2)
theme_bw()$legend.key$colour
#> [1] NA
theme_gray()$legend.key$colour
#> [1] "white" Created on 2019-03-18 by the reprex package (v0.2.1.9000) |
I may have mixed them up. The borders seem to be causing trouble (uneven glyph size), so it may be better to remove them and to create spacing between the keys in a different manner. |
@clauswilke & @yutannihilation : is there any reason why |
There's no good principled reason. It's just that the way legend drawing is currently implemented, adding variable vertical spacing between legend key boxes will not be trivial to implement. |
Looking at it again, setting |
If I'm reading the consensus correctly, I think we can close this particular issue by ensuring that I think this only occurs once, in the Line 172 in b560662
This will probably cause a lot of dopplegangers to change, which would also have to be validated as part of the PR (just describing this as I'm about to tag it for tidy developer day). |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
Hello,
I noticed there was difference in the vertical space between legend keys when switching between themes e.g. from
theme_grey
totheme_bw
(see the reprex below). I wonder what was the cause of that?Thanks!
The text was updated successfully, but these errors were encountered: