Skip to content

Facet: new method setup_panel_params to interact panel_params #6397

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 3 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ggplot2 (development version)

* Facet gains a new method `setup_panel_params` to interact with the panel_params setted by Coord object (@Yunuuuu, #6397, #6380)
* `position_fill()` avoids stacking observations of zero (@teunbrand, #6338)
* New `layer(layout)` argument to interact with facets (@teunbrand, #3062)
* New `stat_connect()` to connect points via steps or other shapes
Expand Down
5 changes: 5 additions & 0 deletions R/facet-.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ NULL
#' the default behaviour of one or more of the following methods:
#'
#' - `setup_params`:
#'
#' - `setup_panel_params`: modifies the x and y ranges for each panel. This is
#' used to allow the `Facet` to interact with the `panel_params`.
#'
#' - `init_scales`: Given a master scale for x and y, create panel
#' specific scales for each panel defined in the layout. The default is to
#' simply clone the master scale.
Expand Down Expand Up @@ -90,6 +94,7 @@ Facet <- ggproto("Facet", NULL,
map_data = function(data, layout, params) {
cli::cli_abort("Not implemented.")
},
setup_panel_params = function(self, panel_params, coord, ...) panel_params,
init_scales = function(layout, x_scale = NULL, y_scale = NULL, params) {
scales <- list()
if (!is.null(x_scale)) {
Expand Down
5 changes: 4 additions & 1 deletion R/layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,15 @@ Layout <- ggproto("Layout", NULL,
scales_x <- self$panel_scales_x[self$layout$SCALE_X[index]]
scales_y <- self$panel_scales_y[self$layout$SCALE_Y[index]]

self$panel_params <- Map(
panel_params <- Map(
self$coord$setup_panel_params,
scales_x, scales_y,
MoreArgs = list(params = self$coord_params)
)[order] # `[order]` does the repeating

# Let Facet modify `panel_params` for each panel
self$panel_params <- self$facet$setup_panel_params(panel_params, self$coord)

invisible()
},

Expand Down
2 changes: 2 additions & 0 deletions man/ggplot2-ggproto.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading