VegaLite.jl icon indicating copy to clipboard operation
VegaLite.jl copied to clipboard

Merging legends (or avoiding double legend, or removing a specific legend)

Open briochemc opened this issue 5 years ago • 3 comments

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: VegaLite_issue

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)

briochemc avatar Mar 11 '19 22:03 briochemc

I think this is https://github.com/vega/vega-lite/issues/3797?

davidanthoff avatar Mar 14 '19 19:03 davidanthoff

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) 🙂

briochemc avatar Mar 15 '19 00:03 briochemc

Yes. We also need to combine legends if a different color and strokeDash is specified for series.

Mastomaki avatar Aug 28 '23 05:08 Mastomaki