Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual legend labels #565

Merged
merged 4 commits into from
Sep 24, 2024
Merged

Manual legend labels #565

merged 4 commits into from
Sep 24, 2024

Conversation

jkrumbiegel
Copy link
Member

Allows to use visual(label = ...) to include layers in the legend without them using any legendable scales. Otherwise, adding layers that are included in the legend always requires making one-element categorical scales, which is an annoying overhead. And it's arbitrary what scale to use for a one-element legend, but of course the scale chosen affects the visual output. For example, if one wants a line with default color, you cannot use the color aesthetic because that will override the color. So you kind of arbitrarily would have to use linestyle or something else. With the label keyword, this is much simpler:

df_subjects = (; x = repeat(1:10, 10), y = cos.(1:100), id = repeat(1:10, inner = 10))
df_func = (; x = range(1, 10, length = 20), y = cos.(range(1, 10, length = 20)))
    
spec1 = data(df_subjects) * mapping(:x, :y, group = :id => nonnumeric) * visual(Lines, linestyle = :dash, color = (:black, 0.2), label = "Subject data")
spec2 = data(df_func) * mapping(:x, :y) * (visual(Lines, color = :tomato) + visual(Scatter, markersize = 12, color = :tomato, strokewidth = 2)) * visual(label = L"\cos(x)")
    
draw(spec1 + spec2)
image

@jkrumbiegel jkrumbiegel merged commit a2e749a into master Sep 24, 2024
5 checks passed
@jkrumbiegel jkrumbiegel deleted the jk/manual-legend-labels branch September 24, 2024 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant