AlgebraOfGraphics.jl
AlgebraOfGraphics.jl copied to clipboard
Different categorical X/Y scales across facets
using layout = dims(1) one can currently create a facet layout where each x or y axis is separate, but only if the data is continuous:
df = (
x1 = [1, 2, 3],
x2 = [4, 5, 6],
y1 = [7, 8, 9],
y2 = [10, 11, 12],
)
data(df) * mapping([:x1, :x2], [:y1, :y2], layout = dims(1)) * visual(Scatter) |> draw(scales(Layout = (; palette = [(1, 1), (2, 1)])))
(never mind the empty big legend, that's a separate bug)
This technique doesn't work with categorical data though, because the internal processing works such that categorical scales are determined together across all facets (unlike continuous, which are determined per facet first and potentially merged later).
df = (
x1 = ["A", "B", "C"],
x2 = ["D", "E", "F"],
y1 = [7, 8, 9],
y2 = [10, 11, 12],
)
data(df) * mapping([:x1, :x2], [:y1, :y2], layout = dims(1)) * visual(Scatter) |> draw(scales(Layout = (; palette = [(1, 1), (2, 1)])))
The X/Y scales are actually special because they can be separated, unlike the scales needing a legend or colorbar (unless we use one legend/colorbar per facet, but at that point we can also just plot multiple plots). It would be nice if we could visualize completely unrelated categorical scales on different facets while still sharing things like continuous colorbars or color groups.