Repository navigation
Conversation
Merge branch 'main' into cleanup_legend_code # Conflicts: # R/guide-legend.R
This was referenced Nov 27, 2023
This reverts commit 148006f.
teunbrand
commented
Nov 27, 2023
Comment on lines
+777
to
+782
| e1$size <- (e2$size %||% rel(1)) * unclass(e1$size) | ||
| } | ||
|
|
||
| # Calculate relative linewidth | ||
| if (is.rel(e1$linewidth)) { | ||
| e1$linewidth <- e2$linewidth * unclass(e1$linewidth) | ||
| e1$linewidth <- (e2$linewidth %||% rel(1)) * unclass(e1$linewidth) |
Collaborator
Author
There was a problem hiding this comment.
If e2 has NULL size/linewidth, this used to result in numeric(0) as size/linewidth. {grid} cannot deal with 0-length gpar settings.
Collaborator
Author
|
OK, so the main idea here is that we can abstract away most of the theme-guide interaction fuss, by just having the guide carry an internal theme that can be added to the plot's theme. However, this is currently also fussy due to the following behaviours of
devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
add_theme(
theme(text = element_blank()), # plot theme
theme(text = element_text(inherit.blank = TRUE)) # guide theme
)$text |> class()
#> [1] "element_text" "element"
add_theme(
theme(text = element_text()), # plot theme
theme(text = NULL) # guide theme
)$text
#> NULL
add_theme(
theme(text = ggtext::element_markdown()), # plot theme
theme(text = element_text(hjust = 0.5)) # guide theme
)
#> Error:
#> ! Problem merging the `text` theme element
#> Caused by error in `merge_element()` at ggplot2/R/theme.R:540:7:
#> ! Only elements of the same class can be mergedCreated on 2023-11-27 with reprex v2.0.2 For now, I've worked around this by making a custom theme merging function, but maybe there are smarter solutions that I couldn't come up with. |
Merged
Collaborator
Author
|
Closing this in favour of #5554 |
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.
The legend code is lettered with all sorts of fussing about theme/element settings. This PR aims to to limit that clutter and make the reasoning about guide/theme interaction much clearer.
Essentially, it implements #5348 internally and passes around an
internal_themeobject that will get merged with the plot's theme. This has the following advantages:Guide$setup_elements()becomes the pure place to break theme inheritance without overriding guide-level user input.Guide$override_elements()becomes the place to override guide-level user input.It made the concession that expression vectors are no longer right-aligned by default (see #4814), as it seemed just very out-of-place to me. Please let me know if this should be preserved.
Current blockers:
merge_element()guide_colourbar()#5455 gives a changed visual test that is changed and should probably be adressed before merging this.