Conversation
| if (npscales$n() > 0) { | ||
| lapply(data, npscales$train_df) | ||
| data <- lapply(data, npscales$map_df) | ||
| plot$key_data <- npscales$key_data(data) |
There was a problem hiding this comment.
Checking the data has to happen before the defaults are filled in and after_scale() modifications are applied. Otherwise the information might be lost. I gave the scales list a method to check the data. The downside is that we have to check all the data regardless of whether the scale has a legend guide, as that isn't resolved at this point.
| } | ||
| present | ||
| }, logical(length(pal))) | ||
| list(aesthetics = aes, data = data_frame0(pal = pal, member = out)) |
There was a problem hiding this comment.
At this point, member is a length(pal) * length(data) logical matrix tracking whether a palette value was seen.
There was a problem hiding this comment.
Also aes can be a vector, e.g. c("colour", "fill"). The inclusion/exclusion rule in the guide only needs to match one of the aesthetics, not all, to be included.
|
Closing this PR in favour of #5502 |
This PR aims to fix #3648. This PR is mutually incompatible with #3649.
Briefly, it automatically checks whether the key value is actually in the data and doesn't draw keys when it isn't. This contrasts with the approach taken in #3649, where the user is given more control.
Less briefly: it performs this check when
show.legend = NA, which is the default. Whenshow.legend = TRUE, is draws the keys regardless of presence in the layer data. To get back the old behaviour and you have multiple legends, you'd have to be specific to include a layer in the keys of a particular legend, for exampleshow.legend = c(colour = TRUE).A small demo from #3648 (comment). Note how there is no point displayed for the 'regression line' key, and no line for the 'points' key.
Created on 2023-05-09 with reprex v2.0.2