-
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
Extracting guide data (version 3) #5506
Conversation
Merge branch 'main' into guide_data3 # Conflicts: # NAMESPACE
I've renamed the function to |
R/guides-.R
Outdated
#' @param i,j An integer giving a row (i) and column (j) number of a facet for | ||
#' which to return position guide information. |
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.
How does this play with facets from extension packages that might not adhere to a strict grid of panels?
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.
Depends on how the facets handle the layout I suppose. From my own package, facet_manual()
has .LEFT
, .RIGHT
, .TOP
and .BOTTOM
instead of ROW
and COL
, so it won't work.
devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
library(ggh4x)
#>
#> Attaching package: 'ggh4x'
#>
#> The following object is masked from 'package:ggplot2':
#>
#> guide_axis_logticks
ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
facet_manual(
~ cyl, design = matrix(c(1,1,NA,NA,NA,2,2,NA,NA,NA,3,3), nrow = 4)
)
get_guide_data(last_plot(), aesthetic = "x", i = 1, j = 1)
#> NULL
Created on 2023-12-14 with reprex v2.0.2
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.
Maybe we should just allow a single index to not force a tabular layout. I know that would require some knowledge about how the facet lays out the panels but this is not something for the standard user anyway
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.
basically use [[
indexing rather than [
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.
I like that idea, and match PANEL
instead of ROW
/COL
. I think PANEL
should be used in most facet extensions, I'd think.
I'm assuming that Thomas' approval still holds after implementing his suggestions, so I'll go ahead and merge this in. |
This PR aims to fix #5004 and replaces #5337.
Briefly, it defines the new
guide_data()
function to programatically access values and labels of axes and legends. More motivation is described in #5096.Because guides are now build in
ggplot_build()
, we can extract the keys more cleanly than #5337. That this PR's footprint more focussed and minimal.Examples (same as #5337):
Created on 2023-11-03 with reprex v2.0.2