-
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
Custom guide #5496
Custom guide #5496
Conversation
While possible I don't think we should advocate the latter use as it muddies the whole guide concept |
Yeah agreed, but I don't think we should disallow it either because it has some use-cases. One of them is if you plot a map of a country and you'd want to display the world as a guide, highlighting the country. |
Merge branch 'main' into guide_custom # Conflicts: # R/guides-.R
Adapted the PR to plumbing in #5483 |
# Assign empty guides if there are no non-position scales | ||
plot$guides <- guides_list() | ||
# Only keep custom guides if there are no non-position scales | ||
plot$guides <- plot$guides$get_custom() |
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.
Can you elaborate on this change?
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.
Sure, in the absence of non-position (NP) scales, we still want to render the custom guides.
Previously, if there were no NP scales, there'd be no need to render any NP guides, so we could set the guides list to empty (as position guides have been absorbed already by the coord).
However, since custom guides aren't attached to a scale, setting the guides list to empty would also discard the custom guides. Instead, we extract only the custom guides if there are no NP scales. In absence of any custom guides, the plot$guides$get_custom()
just returns an empty guides list.
Merge branch 'main' into guide_custom # Conflicts: # man/ggplot2-ggproto.Rd
This PR aims to fix #5416.
Briefly, it introduces
guide_custom()
for drawing arbitrary grobs alongside regular legends.In some more detail:
Guides$build()
because these guides don't have associated scales that train them (nor should they, but the assumption was that there is a scale associated to a guide).A demonstration:
I also realised that it makes it easy to make inset plots with this guide, as you can just pass a rendered plot as the grob.
Created on 2023-10-26 with reprex v2.0.2