@@ -301,12 +301,19 @@ Guides <- ggproto(
301
301
horizontal = c(" center" , " top" )
302
302
)
303
303
304
- # Setup and train on scales
304
+ # Extract the non-position scales
305
305
scales <- scales $ non_position_scales()$ scales
306
306
if (length(scales ) == 0 ) {
307
307
return (no_guides )
308
308
}
309
- guides <- self $ setup(scales )
309
+
310
+ # Ensure a 1:1 mapping between aesthetics and scales
311
+ aesthetics <- lapply(scales , `[[` , " aesthetics" )
312
+ scales <- rep.int(scales , lengths(aesthetics ))
313
+ aesthetics <- unlist(aesthetics , FALSE , FALSE )
314
+
315
+ # Setup and train scales
316
+ guides <- self $ setup(scales , aesthetics = aesthetics )
310
317
guides $ train(scales , theme $ legend.direction , labels )
311
318
if (length(guides $ guides ) == 0 ) {
312
319
return (no_guides )
@@ -343,28 +350,16 @@ Guides <- ggproto(
343
350
default = self $ missing ,
344
351
missing = self $ missing
345
352
) {
346
-
347
- if (is.null(aesthetics )) {
348
- # Aesthetics from scale, as in non-position guides
349
- aesthetics <- lapply(scales , `[[` , " aesthetics" )
350
- scale_idx <- rep(seq_along(scales ), lengths(aesthetics ))
351
- aesthetics <- unlist(aesthetics , FALSE , FALSE )
352
- } else {
353
- # Scale based on aesthetics, as in position guides
354
- scale_idx <- seq_along(scales )[match(aesthetics , names(scales ))]
355
- }
356
-
357
353
guides <- self $ guides
358
354
359
355
# For every aesthetic-scale combination, find and validate guide
360
- new_guides <- lapply(seq_along(scale_idx ), function (i ) {
361
- idx <- scale_idx [i ]
356
+ new_guides <- lapply(seq_along(scales ), function (idx ) {
362
357
363
358
# Find guide for aesthetic-scale combination
364
359
# Hierarchy is in the order:
365
360
# plot + guides(XXX) + scale_ZZZ(guide = XXX) > default(i.e., legend)
366
361
guide <- resolve_guide(
367
- aesthetic = aesthetics [i ],
362
+ aesthetic = aesthetics [idx ],
368
363
scale = scales [[idx ]],
369
364
guides = guides ,
370
365
default = default ,
0 commit comments