Behaviour of legend in AlgebraOfGraphics.jl

Hi, I have made a MWE to show the behaviour I would like to avoid. I am plotting two curves, one of them with points and errobars, the other with lines. There are two problems. When avoiding the errorbars, in the legend the items appear with both points and lines. When plotting the errorbars, the items appear with polygons (rectangles) instead of the correct markers. Maybe I have some error in the mapping?
Here is the MWE of the second case:

n = 20
df_a = DataFrame(grp=fill("a", n), x=collect(1:n), y=fill(2, n))
df_b = DataFrame(grp=fill("b", n), x=collect(1:n), y=fill(3, n), z=fill(0.3, n))

set_aog_theme!()
size_inches = (6.2*2, 3*2)
size_pt = 72 .* size_inches
fig = Figure(resolution = size_pt, fontsize = 30)
gridpos = fig[1, 1]
plt_a = data(df_a) *
    mapping(:x => L"x", :y=> L"y"; color = :grp => "", marker=:grp=> "", linestyle = :grp => "") *
    visual(Lines, linewidth=lw)
plt_b = data(df_b) *(
    mapping(:x => L"x", :y=> L"y"; color = :grp => "", marker=:grp=>"", linestyle= :grp => "") *
    visual(Scatter)+
    mapping(:x => L"x",:y=> L"y",:z;color=:grp=> "", marker=:grp=> "", linestyle = :grp => "")*visual(Errorbars))
f = draw!(gridpos, plt_a+plt_b, axis=(;limits=((0,n),(0,4)),
    xgridvisible=false, ygridvisible=false))
legend!(gridpos, f; tellwidth=false, halign=:center, valign=:bottom, margin=(10, 10, 10, 10), patchsize=(20,10))

display(fig)
leg = fig.content[2]
leg_items = leg.blockscene.children[1].plots
display(leg_items)

When displaying fig.content[2].blockscene.childer[1].plots it can be seen that there are 3 polygons. I think that the first one is correct, but not the other two.
Here is the plot for the second case.
![image|690x333](upload://lVVF5c2GCPhJmnKJv73rpnoCu1z.png
Here is the plot for the first case (without errobars):


There it can be seen that in the legend a shouldn’t have a point while b should’t have the line segment.
Thank you very much.

Here is a somewhat more minimal MWE that’s easier to experiment with:

using AlgebraOfGraphics, CairoMakie

n = 20
df_a = DataFrame(grp=fill("a", n), x=collect(1:n), y=fill(2, n))
df_b = DataFrame(grp=fill("b", n), x=collect(1:n), y=fill(3, n), z=fill(0.3, n))

set_aog_theme!()

xy_map = mapping(:x, :y);
xyz_map = mapping(:x,:y,:z);
fmt_map = mapping(color = :grp => "", linestyle = :grp => "", marker=:grp=> "");

plt_a = data(df_a) * fmt_map * xy_map * visual(Lines);
plt_b = data(df_b) * fmt_map * xy_map * visual(Scatter);
plt_eb = data(df_b) * fmt_map * xyz_map * visual(AlgebraOfGraphics.Errorbars);

fig = draw(plt_a + plt_b + plt_eb)

# Squares in legend, even if just the errorbars are plotted
# fig = draw(plt_eb)

Unfortunately, my experimentation did not produce an answer. Hopefully someone with more expertise in Makie can figure this out.

1 Like

Thank you very much for trying to solve the problem and for improving the MWE. I think that what is happening is that if one plots df_a with lines and df_b with points, in the legend it displays both points and lines in both items.
For example, lets look at the even simpler MWE based on @hendri54’s.

using AlgebraOfGraphics, CairoMakie

n = 20
df_a = DataFrame(grp=fill("a", n), x=collect(1:n), y=fill(2, n))
df_b = DataFrame(grp=fill("b", n), x=collect(1:n), y=fill(3, n), z=fill(0.3, n))

set_aog_theme!()

xy_map = mapping(:x, :y);
xyz_map = mapping(:x,:y,:z);
fmt_map = mapping(color = :grp => "", linestyle = :grp => "", marker=:grp=> "");

plt_a = data(df_a) * fmt_map * xy_map * visual(Lines);
plt_b = data(df_b) * fmt_map * xy_map * visual(Scatter);
plt_eb = data(df_b) * fmt_map * xyz_map * visual(AlgebraOfGraphics.Errorbars);

fig = draw(plt_a + plt_b)

If additionally one plots errorbars it also adds the rectangles in the legend. I have tested it by printing the field fig.content[2].blockscene.childer[1].plots.
I have also tried removing the kwarg linestyle=:grp for plt_b and removing marker:grp for plt_a, but in that way it gives error.
Thanks a lot for any help.