Skip to content

Commit 5b0ea0b

Browse files
Yunuuuuteunbrand
andauthored
Facet: new method setup_panel_params to interact panel_params (#6397)
* `Facet`: new method `setup_panel_params` to interact panel_params * add dots for future extending Co-authored-by: Teun van den Brand <[email protected]> * new bullet --------- Co-authored-by: Teun van den Brand <[email protected]>
1 parent 8b2a764 commit 5b0ea0b

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

Diff for: NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ggplot2 (development version)
22

3+
* Facet gains a new method `setup_panel_params` to interact with the panel_params setted by Coord object (@Yunuuuu, #6397, #6380)
34
* `position_fill()` avoids stacking observations of zero (@teunbrand, #6338)
45
* New `layer(layout)` argument to interact with facets (@teunbrand, #3062)
56
* New `stat_connect()` to connect points via steps or other shapes

Diff for: R/facet-.R

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ NULL
4646
#' the default behaviour of one or more of the following methods:
4747
#'
4848
#' - `setup_params`:
49+
#'
50+
#' - `setup_panel_params`: modifies the x and y ranges for each panel. This is
51+
#' used to allow the `Facet` to interact with the `panel_params`.
52+
#'
4953
#' - `init_scales`: Given a master scale for x and y, create panel
5054
#' specific scales for each panel defined in the layout. The default is to
5155
#' simply clone the master scale.
@@ -90,6 +94,7 @@ Facet <- ggproto("Facet", NULL,
9094
map_data = function(data, layout, params) {
9195
cli::cli_abort("Not implemented.")
9296
},
97+
setup_panel_params = function(self, panel_params, coord, ...) panel_params,
9398
init_scales = function(layout, x_scale = NULL, y_scale = NULL, params) {
9499
scales <- list()
95100
if (!is.null(x_scale)) {

Diff for: R/layout.R

+4-1
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,15 @@ Layout <- ggproto("Layout", NULL,
210210
scales_x <- self$panel_scales_x[self$layout$SCALE_X[index]]
211211
scales_y <- self$panel_scales_y[self$layout$SCALE_Y[index]]
212212

213-
self$panel_params <- Map(
213+
panel_params <- Map(
214214
self$coord$setup_panel_params,
215215
scales_x, scales_y,
216216
MoreArgs = list(params = self$coord_params)
217217
)[order] # `[order]` does the repeating
218218

219+
# Let Facet modify `panel_params` for each panel
220+
self$panel_params <- self$facet$setup_panel_params(panel_params, self$coord)
221+
219222
invisible()
220223
},
221224

Diff for: man/ggplot2-ggproto.Rd

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)