VegaLite.jl
VegaLite.jl copied to clipboard
Merging legends (or avoiding double legend, or removing a specific legend)
Here is a MWE:
using VegaLite, DataFrames
df = DataFrame(x = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4], y = 1:10, style = ["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"])
list_styles = ["B", "A"]
mycolors = ["#000000", "#ee00ff"]
p = df |>
@vlplot(
mark={
:line,
},
encoding={
x={:x, title="x axis"},
y={:y, title="y axis"},
shape={:style, typ="nominal", scale={domain=list_styles}},
color={:style, typ="nominal", scale={range=mycolors, domain=list_styles}}
},
resolve={
scale={
color="independent",
shape="independent"
},
}
)
It produces the following plot:
The problem is that there should only be one legend, the one on the bottom. How does one produce the same figure with only the bottom legend?
I could either
(i) find the correct way to merge the legends (maybe use resolve
differently?), or
(ii) find a way to not output the top legend in the first place, or
(iii) find a way to remove the top legend (somehow my current solution: I save the figure as a pdf and then use Inkscape to remove the top legend...)
(Sorry if the title is not correct)
I think this is https://github.com/vega/vega-lite/issues/3797?
I think this is vega/vega-lite#3797?
Yes, I think. I was hoping for a workaround (that does not involve a vector-graphics editor) 🙂
Yes. We also need to combine legends if a different color and strokeDash
is specified for series.