AlgebraOfGraphics.jl
AlgebraOfGraphics.jl copied to clipboard
Can't map data to `alpha` values
Bug description
I'm trying to map data to the alpha keyword, to create varying transparency for different data points. When I try to do so, it throws a Method error.
Steps to reproduce
This code reproduces the issue:
draw(
data((;
x=rand(100),
y=rand(100),
z=rand(100),
animal=rand(["cat", "dog", "horse"], 100))) *
mapping(:x, :y, color=:animal, alpha=:z) *
visual(Scatter))
It throws an error:
ERROR: MethodError: no method matching to_color(::Tuple{ColorTypes.RGBA{Float32}, Vector{Float64}})
Closest candidates are:
to_color(::Scene, ::Any, ::Cycled)
@ Makie ~/.julia/packages/Makie/6NLuU/src/makielayout/blocks/axis.jl:691
to_color(::Makie.Palette)
@ Makie ~/.julia/packages/Makie/6NLuU/src/conversions.jl:845
to_color(::Symbol)
@ Makie ~/.julia/packages/Makie/6NLuU/src/conversions.jl:854
...
Stacktrace:
[1] (::Makie.var"#111#113")(color::Tuple{ColorTypes.RGBA{Float32}, Vector{Float64}}, a::Float64)
@ Makie ~/.julia/packages/Makie/6NLuU/src/colorsampler.jl:0
[2] map(f::Makie.var"#111#113", scene::Union{…}, arg1::Observable{…}, args::Observable{…}; ignore_equal_values::Bool, priority::Int64)
@ Makie ~/.julia/packages/Makie/6NLuU/src/scenes.jl:160
[3] map
@ ~/.julia/packages/Makie/6NLuU/src/scenes.jl:157 [inlined]
[4] assemble_colors(colortype::Tuple{ColorTypes.RGBA{…}, Vector{…}}, color::Observable{Any}, plot::Scatter{Tuple{…}})
@ Makie ~/.julia/packages/Makie/6NLuU/src/colorsampler.jl:354
[5] color_and_colormap!(plot::Scatter{Tuple{Vector{Point{2, Float32}}}}, colors::Observable{Any})
@ Makie ~/.julia/packages/Makie/6NLuU/src/interfaces.jl:14
[6] color_and_colormap!(plot::Scatter{Tuple{Vector{Point{2, Float32}}}})
@ Makie ~/.julia/packages/Makie/6NLuU/src/interfaces.jl:10
[7] calculated_attributes!
@ Makie ~/.julia/packages/Makie/6NLuU/src/interfaces.jl:64 [inlined]
[8] connect_plot!(parent::Scene, plot::Scatter{Tuple{Vector{Point{2, Float32}}}})
@ Makie ~/.julia/packages/Makie/6NLuU/src/interfaces.jl:253
...
Version info
julia> versioninfo()
Julia Version 1.10.0-rc1
Commit 5aaa9485436 (2023-11-03 07:44 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: macOS (arm64-apple-darwin22.4.0)
CPU: 8 × Apple M2
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 1 on 4 virtual cores
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS =
(src) pkg> status
Status `~/Library/CloudStorage/Dropbox/Documents/Heaviside Research/Clients/Figure8/MAPFRE Initial Analysis/src/Project.toml`
[cbdf2221] AlgebraOfGraphics v0.6.17
[e28b5b4c] Bootstrap v2.4.0
[336ed68f] CSV v0.10.11
[13f3f980] CairoMakie v0.11.3
[8be319e6] Chain v0.5.0
[a93c6f00] DataFrames v1.6.1
[6f286f6a] MultivariateStats v0.10.2
⌅ [2913bbd2] StatsBase v0.33.21
[24678dba] TSne v1.3.0
[c4f8c510] UMAP v0.1.10
[276b4fcb] WGLMakie v0.9.2
Also, an additional note - I spent a bit of time trying to figure out how to manually create a vector of color values that would include my custom alpha, but ran into a couple issues
- I wasn't able to figure out how to duplicate the color group cycling logic
- I realized that even if I got it to work, it would probably mess up my data grouping and legend, because the
colorattribute is used to determine the color groups
Basically what I'd be looking for would be that the color field would still get my Vector{String}, which would set the base color and also the grouping (and the labels on the legend), and then the alpha attribute would basically be added as an additional attribute on top (maybe by multiplying the alpha channel of the existing values from the colormap?)