@@ -861,12 +861,9 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
861861 labels [lengths(labels ) == 0 ] <- " "
862862 # Make sure each element is scalar
863863 labels <- lapply(labels , `[` , 1 )
864-
865- if (any(vapply(labels , is.language , logical (1 )))) {
866- labels <- inject(expression(!!! labels ))
867- } else {
868- labels <- unlist(labels )
869- }
864+ }
865+ if (is.expression(labels )) {
866+ labels <- as.list(labels )
870867 }
871868
872869 labels
@@ -1074,48 +1071,42 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale,
10741071 return (NULL )
10751072 }
10761073
1077- if (is.null(self $ labels )) {
1074+ labels <- self $ labels
1075+ if (is.null(labels )) {
10781076 return (NULL )
10791077 }
10801078
1081- if (identical(self $ labels , NA )) {
1079+ if (identical(labels , NA )) {
10821080 cli :: cli_abort(
10831081 " Invalid {.arg labels} specification. Use {.code NULL}, not {.code NA}." ,
10841082 call = self $ call
10851083 )
10861084 }
10871085
1088- if (is.waiver(self $ labels )) {
1086+ if (is.waiver(labels )) {
10891087 if (! is.null(names(breaks ))) {
1090- return (names(breaks ))
1091- }
1092- if (is.numeric(breaks )) {
1088+ labels <- names(breaks )
1089+ } else if (is.numeric(breaks )) {
10931090 # Only format numbers, because on Windows, format messes up encoding
1094- format(breaks , justify = " none" )
1091+ labels <- format(breaks , justify = " none" )
10951092 } else {
1096- as.character(breaks )
1093+ labels <- as.character(breaks )
10971094 }
1098- } else if (is.function(self $ labels )) {
1099- self $ labels(breaks )
1100- } else {
1101- if (! is.null(names(self $ labels ))) {
1102- # If labels have names, use them to match with breaks
1103- labels <- breaks
1104-
1105- map <- match(names(self $ labels ), labels , nomatch = 0 )
1106- labels [map ] <- self $ labels [map != 0 ]
1107- labels
1108- } else {
1109- labels <- self $ labels
1095+ } else if (is.function(labels )) {
1096+ labels <- labels(breaks )
1097+ } else if (! is.null(names(labels ))) {
1098+ # If labels have names, use them to match with breaks
1099+ map <- match(names(self $ labels ), breaks , nomatch = 0 )
1100+ labels <- replace(breaks , map , labels [map != 0 ])
1101+ } else if (! is.null(attr(breaks , " pos" ))) {
1102+ # Need to ensure that if breaks were dropped, corresponding labels are too
1103+ labels <- labels [attr(breaks , " pos" )]
1104+ }
11101105
1111- # Need to ensure that if breaks were dropped, corresponding labels are too
1112- pos <- attr(breaks , " pos" )
1113- if (! is.null(pos )) {
1114- labels <- labels [pos ]
1115- }
1116- labels
1117- }
1106+ if (is.expression(labels )) {
1107+ labels <- as.list(labels )
11181108 }
1109+ labels
11191110 },
11201111
11211112 clone = function (self ) {
@@ -1351,6 +1342,9 @@ ScaleBinned <- ggproto("ScaleBinned", Scale,
13511342 call = self $ call
13521343 )
13531344 }
1345+ if (is.expression(labels )) {
1346+ labels <- as.list(labels )
1347+ }
13541348 labels
13551349 },
13561350
0 commit comments