-
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
Arbitrary positions for guides #5488
Conversation
Merge branch 'main' into guide_positioning # Conflicts: # R/guides-.R # R/plot-build.R
A few updates.
devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
ggplot(mpg, aes(displ, hwy, colour = cty, shape = factor(cyl), fill = class)) +
geom_point() +
scale_shape_manual(values = 21:25) +
guides(
colour = guide_colourbar(position = "left"),
shape = guide_legend(position = "bottom", direction = "horizontal")
) +
theme(legend.position = "top")
last_plot() + theme(legend.position = "inside",
legend.position.inside = c(0.8, 0.8)) Created on 2023-11-01 with reprex v2.0.2 An open question is whether we should provide theme options to control justification on a per-side basis, for example justify left legends at the bottom and top legends on the right. |
TODO: Add theme settings per position |
Merge branch 'main' into guide_positioning # Conflicts: # R/guide-legend.R # man/guide_legend.Rd
Now always includes rows/columns for every position and a |
Merge branch 'main' into guide_positioning # Conflicts: # R/guides-.R
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Merge branch 'main' into guide_positioning # Conflicts: # R/guides-.R
Thanks for the review Thomas! |
* colourbar size is defined in npcs * backport `unitType` * guide assembly preserves null units * Handle null units at guide boxes * set legend size to 1npc during build * better unit recognitionin R3.6 * smart distribution of null units * better detection of relative legend sizes * document use of null units * Add tests * Adapt to #5488 * Fix title spacing bug
When a plot has multiple guides, we're currently confined to exactly 1 side of the plot where guides are placed.
This PR adds a
position
argument to guides, that can overrule the side set in the theme.Some details:
Guides$build()
method callsGuides$assemble()
for every position, delivering 5 guide-boxes (left, right, top, bottom and manual), instead of just once for one position.There are still some details to hammer out, namely that the guide direction should follow a custom
position
is set. Notice in the plot below that the colourbar has also changed direction, though it probably shouldn't have. Another thing to hammer out is when a guide declaresposition = "manual"
, but the theme doesn't carry values for manual postions.Created on 2023-10-17 with reprex v2.0.2