Inappropriate scoping of after_scale
variables when resolving legend data
#6264
Labels
after_scale
variables when resolving legend data
#6264
The bug concerns a case that's seemingly specific to
stage(start, after_scale)
, when theafter_scale
expression uses a variable from the layer's after-scale data which is unavailable from the guide data.As a preliminary, we know that after scale expressions are ordinarily resolved against both the guide data (first data printed by trace) and the layer data (second data printed by trace).
One can use a variable from the after scale data like
prop
to remap to thefill
aesthetic usingstage()
, like so. Note that the example turns the legend off for the layer to demonstrate the expected output:Now, with the legend turned back on, the plot errors, presumably because while
prop
exists in the after-scale data, it does not exist in the guides data.Since aes expressions are resolved via tidy-eval, this also leads to a surprising behavior where
prop
gets scoped in a parent environment, when available, to resolve the guide data.Two related behaviors worth noting:
after_scale
is specified, the layer does not generate a legend at all for the aesthetic:stage(start, after_scale)
is valid for both sets of data, there is no error and the legend reflects the after-scale transformation.The text was updated successfully, but these errors were encountered: