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

Use `alpha` for grouping

Open greimel opened this issue 2 years ago • 1 comments

Example 1: BarPlot

image

bar_df = DataFrame(
	x = ["a", "a", "a", "b", "b"],
	y = [1, 1, 1, 1, 1],
	grp2 = "h" .* string.([1, 2, 1, 2, 1]),
	grp = "g" .* string.(1:5)
)

data(bar_df) * mapping(:x, :y, stack=:grp, color=:x, alpha=:grp2) * visual(BarPlot) |> draw

Example 2: Scatter

image

n = 300
df = DataFrame(
	x = rand(n), 
	y = rand(n), 
	grp = rand(["a", "b", "c"], n),
	grp2 = rand(["x", "y", "z"], n),
	grp3 = rand(["l", "m", "n"], n)
)

data(df) * mapping(:x, :y, alpha = :grp, color=:grp2, layout=:grp3) * visual(Scatter) |> draw

Example 3: Lines

image

lines_df = let
	T = 100
	t = Int[]
	x = Float64[]
	grp1 = String[]
	grp2 = String[]
	grp3 = String[]

	grps = ["a", "b", "c"]
	
	for i ∈ 1:length(grps)
		for j ∈ 1:length(grps)
			for k ∈ 1:length(grps)
				append!(t, 1:T)
				append!(x, cumsum(randn(T)))
				append!(grp1, fill("1" * grps[i], T))
				append!(grp2, fill("2" * grps[j], T))
				append!(grp3, fill("3" * grps[k], T))
			end
		end
	end

	DataFrame(; t, x, grp1, grp2, grp3)
end

data(lines_df) * mapping(:t, :x, alpha = :grp1, color=:grp2, layout=:grp3) * visual(Lines) |> draw

greimel avatar Mar 31 '23 14:03 greimel

This would be very handy when highlighting a subset of points in a slide show. I'm looking forward to this! :rocket:

jonas-schulze avatar Jun 14 '23 12:06 jonas-schulze