-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Refactor guide styling #5554
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
Merged
Merged
Refactor guide styling #5554
Conversation
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
Merge branch 'main' into guide_themes # Conflicts: # tests/testthat/_snaps/guides/left-aligned-legend-key.svg
teunbrand
commented
Dec 1, 2023
@@ -274,6 +279,7 @@ Guide <- ggproto( | |||
# Converts the `elements` field to proper elements to be accepted by | |||
# `element_grob()`. String-interpolates aesthetic/position dependent elements. | |||
setup_elements = function(params, elements, theme) { | |||
theme <- add_theme(theme, params$theme) |
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.
This is the crucial step.
thomasp85
reviewed
Dec 4, 2023
Merge branch 'main' into guide_themes # Conflicts: # R/guide-bins.R # R/guide-colorbar.R # R/guide-legend.R # R/theme-elements.R # R/theme.R # man/guide_bins.Rd # man/guide_coloursteps.Rd # man/guide_legend.Rd # man/theme.Rd
Merge branch 'main' into guide_themes # Conflicts: # R/guide-colorbar.R # R/guide-legend.R # man/guide_bins.Rd # man/guide_colourbar.Rd # man/guide_coloursteps.Rd # man/guide_legend.Rd
thomasp85
requested changes
Dec 11, 2023
a14493b is about the guide stretching stuff, right? |
And long title placement, yes |
thomasp85
approved these changes
Dec 13, 2023
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
Thanks Thomas! |
teunbrand
added a commit
to teunbrand/ggplot2
that referenced
this pull request
Dec 20, 2023
Merged
teunbrand
added a commit
that referenced
this pull request
Dec 22, 2023
* Apply #5554 to `guide_custom()` * build in early exit
thomasp85
pushed a commit
that referenced
this pull request
Feb 23, 2024
* Apply #5554 to `guide_custom()` * build in early exit
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.
This PR aims to fix #5348 and also fixes #5539, fixes #5540 and fixes #5541 and implements #5473 (comment).
Briefly, it is quite a beefy PR that adds a
theme
argument to allguide_*()
functions and adds guide style elements totheme()
.Less briefly; I could not find a satisfactory way to simplify guide styling without breaking some backward compatibility. I attempted this in #5512, but that PR added as much complexity as it took away. The crux of the PR is this:
theme()
function has new arguments for styling guides, likelegend.frame
,legend.ticks
etc.guide_*()
functions no longer have style arguments, likeframe
,ticks
, etc.guide_*(theme = theme(...))
This allows one to change the look of an individual guide with, for example, a preset theme:
In addition, all guide style options are now settable from the plot's theme:
While retaining flexibility in individual guides.
The 'old' options still work, but are passed through the
...
argument and are undocumented.Also, the 'old' options are soft-deprecated so developers will start seeing warnings about them:
Created on 2023-12-01 with reprex v2.0.2
Some additional notes:
theme()
is already widely used to style non-data elements of the plot, so the way to style guides should be familiar.(plot_theme %||% guide_defaults) + guide_theme
(with%||%
applied element-wise, and+
meaningadd_theme()
). This should allow for easier maintenance of the guides, as well as make it easier to extend guides.guide_colourbar()
has white ticks by default,guide_bins()
has black ticks by default andguide_coloursteps
has hidden ticks by default.legend.key.spacing
is now set to the half the theme'sbase_size
, which already is the default in 99% of legends except in the 1% where the legend doesn't have a title. Previously, it was half the title size, and if that was missing half the label size and if that was missing 5.5 points. This resulted in 1 visual snapshot without a legend title changing slightly. The additional text margins introduced in Rework legend spacing #5456 also derive from this setting for symmetry reasons.