Skip to content

Commit 15ddc22

Browse files
authored
enable legend drawing for list data columns (#2920)
1 parent 05dfaea commit 15ddc22

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

R/guide-legend.r

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,12 @@ guide_train.legend <- function(guide, scale, aesthetic = NULL) {
202202
return()
203203
}
204204

205-
key <- as.data.frame(
206-
setNames(list(scale$map(breaks)), aesthetic %||% scale$aesthetics[1]),
207-
stringsAsFactors = FALSE
208-
)
205+
# in the key data frame, use either the aesthetic provided as
206+
# argument to this function or, as a fall back, the first in the vector
207+
# of possible aesthetics handled by the scale
208+
aes_column_name <- aesthetic %||% scale$aesthetics[1]
209+
# need to make a tibble here in case the scale returns a list column
210+
key <- tibble(!!aes_column_name := scale$map(breaks))
209211
key$.label <- scale$get_labels(breaks)
210212

211213
# Drop out-of-range values for continuous scale

0 commit comments

Comments
 (0)