Arbitrary positions for guides#5488
Merged
teunbrand merged 40 commits intotidyverse:mainfrom Dec 8, 2023
Merged
Conversation
Merge branch 'main' into guide_positioning # Conflicts: # R/guides-.R # R/plot-build.R
Collaborator
Author
|
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. |
Collaborator
Author
|
TODO: Add theme settings per position |
Merge branch 'main' into guide_positioning # Conflicts: # R/guide-legend.R # man/guide_legend.Rd
Collaborator
Author
|
Now always includes rows/columns for every position and a |
teunbrand
commented
Nov 21, 2023
thomasp85
requested changes
Nov 21, 2023
thomasp85
reviewed
Nov 22, 2023
Merge branch 'main' into guide_positioning # Conflicts: # R/guides-.R
Merge branch 'main' into guide_positioning # Conflicts: # R/guides-.R
Collaborator
Author
|
Thanks for the review Thomas! |
teunbrand
added a commit
to teunbrand/ggplot2
that referenced
this pull request
Dec 11, 2023
Merged
teunbrand
added a commit
that referenced
this pull request
Dec 11, 2023
* 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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
positionargument 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
positionis 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