Current advice on stacked bar plots with Makie

This functionality used to reside in StatsMakie, but AlgebraOfGraphics doesn’t seem to have it. I also can’t find it in the base Makie docs.

In StatsPlots, this would be:

julia> using DataFrames, StatsPlots

julia> df = DataFrame(x=1:10, y1 = rand(10), y2 = rand(10) .* 2);

julia> groupedbar(hcat(df.y1, df.y2), bar_position=:stack)

to get

I can get the same thing with Makie manually:

julia> using CairoMakie

julia> fig = Figure();

julia> ax = Axis(fig[1,1]);

julia> barplot!(ax, df.x, df.y1 .+ df.y2, color=:blue)
BarPlot{Tuple{Vector{Point{2, Float32}}}}

julia> barplot!(ax, df.x, df.y2, color=:orange)
BarPlot{Tuple{Vector{Point{2, Float32}}}}

to get

But this could get tedious. Is there a better way?

PS - perhaps this could have been posted as a reply to this old thread showing how to do the same thing in a bunch of other plotting libraries, but I thought it could use the extra visibility.

1 Like

Relevant prs:

1 Like

Ah, thank you. I can steal some code from those until there’s a more official solution.