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
439 stars 45 forks source link

Non-categorical faceting #301

Open grahamas opened 3 years ago

grahamas commented 3 years ago

Faceting fails silently when the faceted variable is numeric.

df = (x=rand(100), y=rand(100), j=rand(1:6, 100))
plt = data(df) * mapping(:x, :y, row=:j)
draw(plt)

This plots all points in a single facet.

(especially important due to #183)

AoG v0.5.4, julia v1.6.3

andreasnoack commented 2 years ago

Possibly related to this. If I use a numerical grouping variable in the examples in https://github.com/JuliaPlots/AlgebraOfGraphics.jl/issues/372 then I get

julia> draw(data(df) * mapping(:x, col=:gr) * histogram(), facet=(;linkxaxes=:minimal))
ERROR: MethodError: no method matching _histogram(::Tuple{Vector{Float64}}; col=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1  …  2, 2, 2, 2, 2, 2, 2, 2, 2, 2], datalimits=((-2.6933590201832143, 102.04534348636523),), closed=:left, normalization=:none)
Closest candidates are:
  _histogram(::Tuple; bins, weights, normalization, datalimits, closed) at ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/transformations/histogram.jl:24 got unsupported keyword argument "col"
Stacktrace:
  [1] kwerr(::NamedTuple{(:col, :datalimits, :closed, :normalization), Tuple{Vector{Int64}, Tuple{Tuple{Float64, Float64}}, Symbol, Symbol}}, ::Function, ::Tuple{Vector{Float64}})
    @ Base ./error.jl:163
  [2] (::AlgebraOfGraphics.var"#189#190"{NamedTuple{(:datalimits, :closed, :normalization), Tuple{Tuple{Tuple{Float64, Float64}}, Symbol, Symbol}}})(p::Vector{Vector{Float64}}, n::Dictionaries.Dictionary{Symbol, Any})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/transformations/histogram.jl:49
  [3] (::AlgebraOfGraphics.var"#75#76"{AlgebraOfGraphics.var"#189#190"{NamedTuple{(:datalimits, :closed, :normalization), Tuple{Tuple{Tuple{Float64, Float64}}, Symbol, Symbol}}}, ProcessedLayer})(c::CartesianIndex{1})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/layer.jl:85
  [4] iterate
    @ ./generator.jl:47 [inlined]
  [5] _collect(c::CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, itr::Base.Generator{CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, AlgebraOfGraphics.var"#75#76"{AlgebraOfGraphics.var"#189#190"{NamedTuple{(:datalimits, :closed, :normalization), Tuple{Tuple{Tuple{Float64, Float64}}, Symbol, Symbol}}}, ProcessedLayer}}, #unused#::Base.EltypeUnknown, isz::Base.HasShape{1})
    @ Base ./array.jl:744
  [6] collect_similar(cont::CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, itr::Base.Generator{CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, AlgebraOfGraphics.var"#75#76"{AlgebraOfGraphics.var"#189#190"{NamedTuple{(:datalimits, :closed, :normalization), Tuple{Tuple{Tuple{Float64, Float64}}, Symbol, Symbol}}}, ProcessedLayer}})
    @ Base ./array.jl:653
  [7] map(f::Function, A::CartesianIndices{1, Tuple{Base.OneTo{Int64}}})
    @ Base ./abstractarray.jl:2849
  [8] map(f::AlgebraOfGraphics.var"#189#190"{NamedTuple{(:datalimits, :closed, :normalization), Tuple{Tuple{Tuple{Float64, Float64}}, Symbol, Symbol}}}, processedlayer::ProcessedLayer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/layer.jl:84
  [9] (::AlgebraOfGraphics.HistogramAnalysis{MakieCore.Automatic, MakieCore.Automatic})(input::ProcessedLayer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/transformations/histogram.jl:48
 [10] ProcessedLayer(layer::Layer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/layer.jl:64
 [11] iterate
    @ ./generator.jl:47 [inlined]
 [12] collect(itr::Base.Generator{AlgebraOfGraphics.Layers, Type{ProcessedLayer}})
    @ Base ./array.jl:724
 [13] map
    @ ./abstractarray.jl:2878 [inlined]
 [14] compute_axes_grid(s::Layer; axis::NamedTuple{(), Tuple{}}, palettes::NamedTuple{(), Tuple{}})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/layers.jl:130
 [15] compute_axes_grid(fig::Figure, s::Layer; axis::NamedTuple{(), Tuple{}}, palettes::NamedTuple{(), Tuple{}})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/layers.jl:117
 [16] #226
    @ ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/draw.jl:21 [inlined]
 [17] update
    @ ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/draw.jl:10 [inlined]
 [18] plot!(fig::Figure, s::Layer; axis::NamedTuple{(), Tuple{}}, palettes::NamedTuple{(), Tuple{}})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/draw.jl:21
 [19] (::AlgebraOfGraphics.var"#230#231"{NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}, NamedTuple{(:linkxaxes,), Tuple{Symbol}}, NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}, Layer})(f::Figure)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/draw.jl:46
 [20] update
    @ ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/draw.jl:10 [inlined]
 [21] #draw#229
    @ ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/draw.jl:45 [inlined]
 [22] top-level scope
    @ REPL[34]:1