MakieOrg / AlgebraOfGraphics.jl

An algebraic spin on grammar-of-graphics data visualization in Julia. Powered by the Makie.jl plotting ecosystem.
https://aog.makie.org
MIT License
443 stars 46 forks source link

Make the `color = dims(1)` correspond to the `mapping` for wide data #474

Open pdeffebach opened 1 year ago

pdeffebach commented 1 year ago

Problem description

I am making a line plot with wide data. The command is

p = data(df_collapsed) * mapping(:mean_age, [:N, :U, :B, :W], color = dims(1) => renamer(["N", "U", "B", "W"])) * visual(Lines)

See how I have to repeat ["N", "U", "B", "W"] twice? I should just have to write dims(1) and have it automatically take the name of the lines from the mapping.

pdeffebach commented 1 year ago

Here is an MWE

julia> using AlgebraOfGraphics, GLMakie, DataFrames;

julia> df = DataFrame(x = 1:10, y1 = rand(10) .+ 1, y2 = rand(10) .+ 2);

julia> p = data(df) * mapping(:x, [:y1, :y2], color = dims(1)) * linear();

julia> draw(p)

Which gives

image

I would like the two lines on the graph to be labelled "y1" and "y2" rather than CartesianIndex as is the current behavior.