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

Layering visuals with separate legends #427

Closed
jkrumbiegel opened this issue Sep 13, 2022 · 1 comment · Fixed by #505
Closed

Layering visuals with separate legends #427

jkrumbiegel opened this issue Sep 13, 2022 · 1 comment · Fixed by #505

Comments

@jkrumbiegel
Copy link
Member

I think it's very common that one wants to plot multiple different pieces of a dataset by layering visuals on top of each other. Here are a few examples of this scenario from a quick google search:

image
image
image

The problem is that AlgebraOfGraphics doesn't have this notion of separate-but-together as far as I understand. All data being plotted should come from the same source columns and can be grouped in different nesting levels, but the grouping factors should not be separate. I hope the images make clear what I'm after, just a way to "layer" multiple visuals onto the same plot, and sequentially list them in the legend. It doesn't have to be in separate legend sections, for many plots, a simple list is also sufficient.

This usually arises when one wants to augment a facet plot with let's say, one hlines in each facet which also needs to be described, but doesn't further participate in the grouping and therefore shouldn't be merged into the existing legend entries.

Here's an example, how it currently works:

using AlgebraOfGraphics
using CairoMakie
using DataFrames

df = DataFrame(x = 1:10, y = rand(10), group = "Z")
df2 = DataFrame(x = repeat(1:10, 4), y = rand(40), name = repeat(["A", "B", "C", "D"], inner = 10))

data(df) *
    mapping(:x, :y, color = :group) +
data(df2) *
    mapping(:x, :y, color = :name) * visual(Lines) |> draw

image

As you can see, the scatter was merged together with the lines in the legend, instead of four lines and one scatter.

@jkrumbiegel
Copy link
Member Author

Inspirations from ggplot:

https://github.com/clauswilke/relayer allows to create a separate legend for each facet, as an example.
tidyverse/ggplot2#2570 tracks how they thought about the same problem basically

@jkrumbiegel jkrumbiegel linked a pull request Jul 16, 2024 that will close this issue
7 tasks
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 a pull request may close this issue.

1 participant