-
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
Issue with guide_custom()
messing up alignment of other guides
#5727
Comments
I think textbox grobs from {ggtext} don't self-report the width of the text, making placement somewhat more annoying. library(ggplot2)
library(palmerpenguins)
ggplot(
penguins, aes(x = body_mass_g, y = flipper_length_mm, color = species)
) +
geom_point() +
guides(
custom = guide_custom(
grob = gridtext::textbox_grob(
"Flipper Length (mm)", hjust = 0
)
)
) +
theme(
legend.box = "vertical",
legend.box.just = "left",
legend.location = "plot",
legend.position = "top",
legend.justification = c(0, 1),
legend.background = element_rect(colour = "black")
)
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_point()`). Created on 2024-02-28 with reprex v2.1.0 |
If it's a feature that is missing in gridtext please file an issue there. A PR with a fix would be even better. |
Now I'm starting to doubt library(ggplot2)
library(palmerpenguins)
ggplot(
penguins, aes(x = body_mass_g, y = flipper_length_mm, color = species)
) +
geom_point() +
guides(
custom = guide_custom(
grob = grid::textGrob("Flipper Length (mm)", just = "right")
)
) +
theme(
legend.box = "vertical",
legend.location = "plot",
legend.position = "top",
legend.justification = c(0, 1),
legend.background = element_rect(colour = "black")
)
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_point()`). Created on 2024-02-28 with reprex v2.1.0 |
I've done a bit of investigating and this is going on. For the For the The |
Thank you @teunbrand! This is all super helpful! |
I'm not sure if this is a bug with
ggplot2
or withgridtext
, but I want to add a guide_custom with a custom grob viagridtext
. This messes up the alignment of the color guide. This doesn't happen withgrid::textGrob
.gridtext::textbox_grob
returns agTree
, so maybe that's causing the problem. If this is an issue withgridtext
, feel free to close!Reprex:
Created on 2024-02-28 with reprex v2.1.0
The text was updated successfully, but these errors were encountered: