In layered specs, legends over the same field should be merged but sometimes are not.
See https://github.com/vega/vega-lite/issues/5695, https://github.com/vega/vega-lite/issues/5543, https://github.com/vega/vega-lite/issues/1844#issuecomment-593138857, #6359, https://github.com/vega/vega-lite/issues/3797
A little background for anyone here (like me) who is eagerly waiting for this to be fixed:
This unassigned issue dates back to 2015 and was previously marked as a critical issue for release 2.0.0. Issue #821 actually included a workaround which would modify the resulting vega code to resolve the issue.
Note that there are different variations of this issue. We have fixed some but not others. So some specs that used to not work, work today. See https://github.com/vega/vega-lite/issues/1844 for example. Just wanted to note this that we are continuously improving how legends are being merged.
Most helpful comment
Note that there are different variations of this issue. We have fixed some but not others. So some specs that used to not work, work today. See https://github.com/vega/vega-lite/issues/1844 for example. Just wanted to note this that we are continuously improving how legends are being merged.