# More Barplots

**URL:** <https://discourse.julialang.org/t/more-barplots/137117>\
**Category:** Visualization\
**Tags:** makie, cairomakie\
**Created:** [May 14, 2026, 4:15am UTC](https://discourse.julialang.org/t/more-barplots/137117 "2026-05-14T04:15:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mervyn\_Larrier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mervyn_larrier/32/37709_2.png) [@Mervyn\_Larrier](https://discourse.julialang.org/u/Mervyn_Larrier)\
**Post date:** [May 14, 2026, 4:15am UTC](https://discourse.julialang.org/t/more-barplots/137117/1 "2026-05-14T04:15:27Z")

</div>

Hi all. Round two of figuring out bar plots in Makie. Given the data, I would like to plot one set of data and then stack the other data on top of it. In my last question, my issue was resolved with the n\_dodge attribute being adjusted, but there doesn’t seem to be a similar attribute for stacking the plots. As of now, I can only plot one data set or the other. Bonus points if you include a legend. Any help would be greatly appreciated.

```julia-auto
using CairoMakie

porosity_op = [80,75,77,80,85,90,85]
porosity_tot = [20,21,21,20,23,26,20]
grades = ["ZXF-5Q","ACF-10Q","AXF-3Q","AXF-5Q","AXM-5Q","AXZ-5Q","TM"]

fig = CairoMakie.Figure()
ax = CairoMakie.Axis(fig[1,1], xticks = (1:7, grades), title = "Porosity Percentage")
barplot!(ax2, 1:7,
porosity_tot,
stack = [1,2,1,2,1,2,1], width = 0.5,
) 
 
barplot!(ax, 1:7,
porosity_op,
stack = [1,2,1,2,1,2,1], width = 0.5
)
fig

```

---

<div class="post-metadata">

**Author:** ![icweaver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/icweaver/32/45764_2.png) [@icweaver](https://discourse.julialang.org/u/icweaver)\
**Post date:** [May 14, 2026, 8:54am UTC](https://discourse.julialang.org/t/more-barplots/137117/2 "2026-05-14T08:54:07Z")

</div>

Hey, brother. If I was using vanilla Makie.jl, I might do something like this if I wanted to keep the datasets separate:

```julia
using CairoMakie

fig = Figure()

ax = Axis(fig[1, 1]; xticks = (eachindex(grades), grades), title = "Porosity Percentage")

barplot!(ax, porosity_op;
    color = :cornflowerblue,
    width = 0.5,
    label = "Operational",
)

barplot!(ax, porosity_tot;
    offset = porosity_op,
    color = :orange,
    width = 0.5,
    label = "Total",
)

Legend(fig[1, 2], ax, "Porosity")

fig

```

or just use AoG if the dataset can be expressed in “long” format:

```julia
using CairoMakie, AlgebraOfGraphics

set_aog_theme!() # Looks nice

df_long = (
    porosity = [porosity_op; porosity_tot],
    grp = repeat(["Operational", "Total"]; inner = 7),
    grades = repeat(grades, 2),
)

plt = data(df_long) *
    mapping(:grades => presorted, :porosity => "",
        stack = :grp,
        color = :grp => "Porosity",
    ) *
    visual(BarPlot, width = 0.5)

draw(plt; axis = (; title = "Porosity Percentage"))

```

or wide format too:

```julia
df_wide = (
    porosity_op = [80,75,77,80,85,90,85],
    porosity_tot = [20,21,21,20,23,26,20],
    grades = ["ZXF-5Q","ACF-10Q","AXF-3Q","AXF-5Q","AXM-5Q","AXZ-5Q","TM"],
)

plt = data(df_wide) *
    mapping(:grades => presorted,
        [:porosity_op, :porosity_tot] .=> ["Operational", "Total"];
        stack = dims(1),
        color = dims(1) => "Porosity",
    ) *
    visual(BarPlot, width = 0.5)

draw(plt; axis = (; title = "Porosity Percentage", ylabel = ""))

```

 ![display](https://global.discourse-cdn.com/julialang/original/3X/4/3/43e0c1b4929ce9ea208124bfbaba56330fb70100.png)

Can adjust to taste for how the percentages should combine

---

<div class="post-metadata">

**Author:** ![eteppo](https://avatars.discourse-cdn.com/v4/letter/e/90db22/32.png) [@eteppo](https://discourse.julialang.org/u/eteppo)\
**Post date:** [May 14, 2026, 9:44am UTC](https://discourse.julialang.org/t/more-barplots/137117/3 "2026-05-14T09:44:24Z")

</div>

Using tidy/long-format data can save many headaches. Makie `stack` and `color` attributes appear to expect it.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [May 14, 2026, 10:15am UTC](https://discourse.julialang.org/t/more-barplots/137117/4 "2026-05-14T10:15:06Z")

</div>

The reason stack doesn’t have `nstack` like `ndodge` is that dodging is data independent but stacking is not. So you can’t stack with separate plot objects as all the data has to be available at once to compute the cumsums. There’s generally no crosstalk between separate Makie plot objects.

---

<div class="post-metadata">

**Author:** ![Mervyn\_Larrier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mervyn_larrier/32/37709_2.png) [@Mervyn\_Larrier](https://discourse.julialang.org/u/Mervyn_Larrier)\
**Post date:** [May 14, 2026, 4:08pm UTC](https://discourse.julialang.org/t/more-barplots/137117/5 "2026-05-14T16:08:38Z")

</div>

In my original code, the values are extracted from a tidy format data frame. I switched it around from wide format for the very reason you mentioned as it happens 😆

---

<div class="post-metadata">

**Author:** ![Mervyn\_Larrier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mervyn_larrier/32/37709_2.png) [@Mervyn\_Larrier](https://discourse.julialang.org/u/Mervyn_Larrier)\
**Post date:** [May 14, 2026, 4:09pm UTC](https://discourse.julialang.org/t/more-barplots/137117/6 "2026-05-14T16:09:45Z")

</div>

So I would combine the two data sets and then set the stack that way? Is that the logic?

---

<div class="post-metadata">

**Author:** ![Mervyn\_Larrier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mervyn_larrier/32/37709_2.png) [@Mervyn\_Larrier](https://discourse.julialang.org/u/Mervyn_Larrier)\
**Post date:** [May 14, 2026, 4:19pm UTC](https://discourse.julialang.org/t/more-barplots/137117/7 "2026-05-14T16:19:14Z")

</div>

Good looking out brother, this result is exactly what I was looking for. I’ve never used AoG though. I started using Makie because of how much control it gives you (since I guess you can consider it “low level” or backend), and most things seem easy enough to achieve. Does AoG make CairoMakie that much easier to use? I get the vibe you mainly use AoG, so if you’re down I’d really appreciate your thoughts on it.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [May 14, 2026, 6:01pm UTC](https://discourse.julialang.org/t/more-barplots/137117/8 "2026-05-14T18:01:43Z")

</div>

Yes. AoG does the concatenation for you if there are more datasets, that’s why this particular thing is more convenient there.

---

<div class="post-metadata">

**Author:** ![icweaver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/icweaver/32/45764_2.png) [@icweaver](https://discourse.julialang.org/u/icweaver)\
**Post date:** [May 14, 2026, 9:11pm UTC](https://discourse.julialang.org/t/more-barplots/137117/9 "2026-05-14T21:11:55Z")

</div>

For sure, glad it worked out. I’d say I reach for AlgebraOfGraphics.jl if I am working with structured data, and Makie.jl otherwise these days. The nice thing is that it’s pretty doable to [go back and forth](https://aog.makie.org/stable/FAQs#How-to-combine-AlgebraOfGraphics-with-plain-Makie-plots?) if you ever need to too. And much appreciation to Jules and the rest of the Makie team. Their revamp of the [AoG Palmer Penguins tutorial](https://aog.makie.org/stable/tutorials/intro-i) and wider packages in general really helped things start to click for me

---

<div class="post-metadata">

**Author:** ![Mervyn\_Larrier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mervyn_larrier/32/37709_2.png) [@Mervyn\_Larrier](https://discourse.julialang.org/u/Mervyn_Larrier)\
**Post date:** [May 15, 2026, 3:42am UTC](https://discourse.julialang.org/t/more-barplots/137117/10 "2026-05-15T03:42:10Z")

</div>

When you say structured data, you mean things like data frames, right? Would unstructured data be something like, plotting a function? I haven’t used much outside of CairoMakie, so I think I’ve mostly only worked with structured data; things like experimental observations and the like.  
Also, wow, didn’t even realize one of the creators was helping me! Makes sense how he just knew exactly what my issues were both times!

---

<div class="post-metadata">

**Author:** ![icweaver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/icweaver/32/45764_2.png) [@icweaver](https://discourse.julialang.org/u/icweaver)\
**Post date:** [May 15, 2026, 11:02am UTC](https://discourse.julialang.org/t/more-barplots/137117/11 "2026-05-15T11:02:03Z")

</div>

Right, data frames (or other [Tables.jl compatible objects](https://github.com/JuliaData/Tables.jl/blob/main/INTEGRATIONS.md)), named tuples, etc. If I’m just making a one-off plot or something simple like plotting vector x vs. vector y, I might reach for something like `scatter(x, y)` from vanilla Makie.jl first, although you could always do the same in AoG with `mapping(x, y) |> draw`.

And once things like grouping and categories start to come into the picture, AoG really becomes a natural choice depending on the context. Nowadays, working with [long vs. wide data](https://aog.makie.org/stable/examples/data-manipulations/wide-data#Understanding-Wide-Format-Mappings), or even so-called [“pre-grouped” data](https://aog.makie.org/stable/examples/data-manipulations/pre-grouped-data#Pre-grouped-data) is pretty pleasant.

Yea, this community is dope. Besides getting to just chat with folks that are world experts in their fields, what’s really kept me coming back is the straight up kindness and inclusiveness from everyone involved.
