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

Accept a uer-defined domain of variable

Open lassepe opened this issue 2 years ago • 0 comments

Currently, AoG derives the domain of a value from the observed data. However, if a certain value is never observed in the data, the corresponding value element of the domain is also missing in the visualization.

For example, consider the following case:

using AlgebraOfGraphics
df = [(; x = rand([0, 1]), y = rand(["a", "b"])) for _ in 1:10]
data(df) * mapping(:x, col = :y) * frequency() |> draw

Ideally, this should produce a plot with two columns (for "a" and "b") and each column has two bars (for the frequency of "0" an "1"). However, if we get "unlucky" during sampling, some values may never be observed. For example, y = "a" may never be sampled or x = "0" is never sampled (or the some joint sample, say, (; x = 0, y = "a") may never be observed). All of these cases would lead to either a bar or an entire column missing in the plot.

Of course, AoG cannot know when such a value is missing. Hence, I would like to be able to provide the domain of that variable; e.g.

data(df) * mapping(:x, col = :y; x_domain = [0,1], col_domain = ["a", "b"]) * frequency() |> draw()

I could not find support for this case in the docs. Is this already possible potentially via some low-level tweaks with raw Makie?

lassepe avatar Aug 03 '23 20:08 lassepe