# Current advice on stacked bar plots with Makie

**URL:** https://discourse.julialang.org/t/current-advice-on-stacked-bar-plots-with-makie/57095
**Category:** Visualization
**Tags:** makie
**Created:** [March 13, 2021, 8:46pm UTC](https://discourse.julialang.org/t/current-advice-on-stacked-bar-plots-with-makie/57095 "2021-03-13T20:46:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [March 13, 2021, 8:46pm UTC](https://discourse.julialang.org/t/current-advice-on-stacked-bar-plots-with-makie/57095/1 "2021-03-13T20:46:14Z")

</div>

This functionality [used to reside](http://juliaplots.org/StatsMakie.jl/latest/manual/tutorial/#What-if-I-have-data-instead?-1) in StatsMakie, but AlgebraOfGraphics [doesn’t seem](http://juliaplots.org/AlgebraOfGraphics.jl/stable/search/?q=stack) to have it. I also can’t find it in the base Makie docs.

In StatsPlots, this would be:

```julia
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

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/8/98749c6e7c502483c27c92e70dabe6e630d73296.png)

I can get the same thing with Makie manually:

```julia
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

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/5/d5f6fa943d7d624aba9c544598124485fe12e889.png)

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

PS - perhaps this could have been posted as a reply to [this old thread](https://discourse.julialang.org/t/stacked-bar-graphs/18550/22) showing how to do the same thing in a bunch of other plotting libraries, but I thought it could use the extra visibility.

---

<div class="post-metadata">

### Author: ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)
#### Post date: [March 14, 2021, 1:12am UTC](https://discourse.julialang.org/t/current-advice-on-stacked-bar-plots-with-makie/57095/2 "2021-03-14T01:12:37Z")

</div>

Relevant prs:

[https://github.com/JuliaPlots/AbstractPlotting.jl/pull/640](https://github.com/JuliaPlots/AbstractPlotting.jl/pull/640)  
[https://github.com/JuliaPlots/AbstractPlotting.jl/pull/580](https://github.com/JuliaPlots/AbstractPlotting.jl/pull/580)

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [March 14, 2021, 1:52am UTC](https://discourse.julialang.org/t/current-advice-on-stacked-bar-plots-with-makie/57095/3 "2021-03-14T01:52:41Z")

</div>

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