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

color legend entry

Open SimonDanisch opened this issue 4 years ago • 2 comments

Legend currently doesn't pick up an e.g. markercolor:

df = (
    x = 1:10,
    y = rand(10),
    attr = ["m $i" for i in 1:10],
)
draw(data(df) * mapping(:x, :y, marker=:attr) * visual(Scatter, color=:red))

image

This PR takes uses the color, if it's a single color: image

if multiple colors are used, it defaults back to black:

draw(data(df) * (mapping(:x, :y, marker=:attr) * (visual(Scatter, color=:red, markersize=20) + visual(Scatter, color=:green, markersize=10))))

image

SimonDanisch avatar Jul 07 '21 15:07 SimonDanisch

I don't fully understand what the code does. But what happens if you use color for grouping but there happens to be just one group? (In my opinion, the legend for marker should be black despite there being just one color.)

What about a more general solution that adds all keywords from visual to options (which are then passed on to legend_element)?

(Not sure if that's easily doable, though)

greimel avatar Jul 07 '21 16:07 greimel

I don't fully understand what the code does. But what happens if you use color for grouping but there happens to be just one group? (In my opinion, the legend for marker should be black despite there being just one color.)

I think this PR only considers colors that are given via visual. I confess I'm in two minds about this, I'm not completely sure which is a better default for the legend, whether it is the theme default or the values it encounters in visual (should they all agree). Do you have some intuition as to which is more natural?

Somehow, both things seem reasonable to me, and maybe it's not too bad to briefly change the theme to have red markers (maybe theme can be passed as a keyword to draw, and is merged to the default theme).

piever avatar Jul 08 '21 09:07 piever