@@ -458,25 +458,38 @@ Scale <- ggproto("Scale", NULL,
458
458
cli :: cli_abort(" Not implemented" )
459
459
},
460
460
461
- map_df = function (self , df , i = NULL ) {
461
+ map_df = function (self , df , i = NULL , scale_params = NULL ) {
462
462
if (empty(df )) {
463
463
return ()
464
464
}
465
+ if (is.null(scale_params )) {
466
+ scale_params <- list ()
467
+ }
465
468
466
469
aesthetics <- intersect(self $ aesthetics , names(df ))
467
470
names(aesthetics ) <- aesthetics
468
471
if (length(aesthetics ) == 0 ) {
469
472
return ()
470
473
}
471
474
472
- if (is.null(i )) {
473
- lapply(aesthetics , function (j ) self $ map(df [[j ]]))
475
+ if (" scale_params" %in% names(ggproto_formals(self $ map ))) {
476
+ if (is.null(i )) {
477
+ lapply(aesthetics , function (j ) self $ map(df [[j ]], scale_params = scale_params [[j ]]))
478
+ } else {
479
+ lapply(aesthetics , function (j ) self $ map(df [[j ]][i ], scale_params = scale_params [[j ]]))
480
+ }
474
481
} else {
475
- lapply(aesthetics , function (j ) self $ map(df [[j ]][i ]))
482
+ # Eventually warn if self$map() does not accept scale_params
483
+ if (is.null(i )) {
484
+ lapply(aesthetics , function (j ) self $ map(df [[j ]]))
485
+ } else {
486
+ lapply(aesthetics , function (j ) self $ map(df [[j ]][i ]))
487
+ }
488
+
476
489
}
477
490
},
478
491
479
- map = function (self , x , limits = self $ get_limits()) {
492
+ map = function (self , x , limits = self $ get_limits(), scale_params = NULL ) {
480
493
cli :: cli_abort(" Not implemented" )
481
494
},
482
495
0 commit comments