# How to label multiple histograms in AlgebraOfGraphics

**URL:** <https://discourse.julialang.org/t/how-to-label-multiple-histograms-in-algebraofgraphics/127429>\
**Category:** Visualization\
**Tags:** makie, algebraofgraphics, aog, histogram\
**Created:** [March 27, 2025, 4:48pm UTC](https://discourse.julialang.org/t/how-to-label-multiple-histograms-in-algebraofgraphics/127429 "2025-03-27T16:48:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abhro/32/220753_2.png) [@Abhro](https://discourse.julialang.org/u/Abhro)\
**Post date:** [March 27, 2025, 4:48pm UTC](https://discourse.julialang.org/t/how-to-label-multiple-histograms-in-algebraofgraphics/127429/1 "2025-03-27T16:48:32Z")

</div>

I have a dataset where each column is a list of occurrences. I would like to plot three columns as three histograms within one figure, but I cannot wrap my head around the AlgebraOfGraphics idioms.

Within Makie.jl, I would do

```julia
fig = Figure()
ax = Axis(fig[1,1])

hist!(ax, df[:pf], label = "Plasma frame")
hist!(ax, df[:sf], label = "Shock frame")
hist!(ax, df[:ISM], label = "ISM frame")

axislegend(ax)

fig

```

where `df` is my data source and each of `df[:pf]`, `df[:sf]`, and `df[:ISM]` is a `Vector`.

With AlgebraOfGraphics.jl, I’ve tried

```julia
using AlgebraOfGraphics
import AlgebraOfGraphics as AoG

data = AoG.data(df)
m = AoG.mapping(:pf => "Plasma frame") +
    AoG.mapping(:sf => "Shock frame") +
    AoG.mapping(:ISM => "ISM frame")
hist_layer = AoG.histogram()

layer = data * m * hist_layer

```

The issue I’m having is with labeling each histogram. I know the `=>` Pair syntax labels the axes, but I couldn’t figure out how to add data series labels from the AoG documentation.

---

<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:** [March 27, 2025, 7:18pm UTC](https://discourse.julialang.org/t/how-to-label-multiple-histograms-in-algebraofgraphics/127429/2 "2025-03-27T19:18:09Z")

</div>

The plain label is done via `visual(label = "label")` but then you have to do the colors yourself. Easier would be to pass your three columns as a vector and then use `dims(1)` for color, check this tutorial for reference [Intro to AoG - V - Alternative input data formats | AlgebraOfGraphics](https://aog.makie.org/stable/tutorials/intro-v#Wide-data)

---

<div class="post-metadata">

**Author:** ![Abhro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abhro/32/220753_2.png) [@Abhro](https://discourse.julialang.org/u/Abhro)\
**Post date:** [April 2, 2025, 3:01pm UTC](https://discourse.julialang.org/t/how-to-label-multiple-histograms-in-algebraofgraphics/127429/3 "2025-04-02T15:01:37Z")

</div>

Hi! Thank you so much! This almost gets to the result I want, except the legend is labeled with `CartesianIndex(i,)`. It’s not picking up that the labels for each series should be the column name

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

---

<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:** [April 2, 2025, 8:59pm UTC](https://discourse.julialang.org/t/how-to-label-multiple-histograms-in-algebraofgraphics/127429/4 "2025-04-02T20:59:40Z")

</div>

You can do that via `renamer` like in the tutorial. The dimensions are not automatically named by input columns, because they are not necessarily defined like that. But maybe in the future that could be built in as a convenient shortcut or something

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [April 2, 2025, 9:06pm UTC](https://discourse.julialang.org/t/how-to-label-multiple-histograms-in-algebraofgraphics/127429/5 "2025-04-02T21:06:01Z")

</div>

Oh yeah the lack of automatic naming was an annoyance I had that I never mentioned.

It would be really cool if AlgebraOfGraphics.jl leveraged table-level metadata, particularly the `label` field.

---

<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:** [April 3, 2025, 6:35am UTC](https://discourse.julialang.org/t/how-to-label-multiple-histograms-in-algebraofgraphics/127429/6 "2025-04-03T06:35:47Z")

</div>

You had mentioned it 🙂 [Make the `color = dims(1)` correspond to the `mapping` for wide data · Issue #474 · MakieOrg/AlgebraOfGraphics.jl · GitHub](https://github.com/MakieOrg/AlgebraOfGraphics.jl/issues/474)

I still haven’t looked into how that might be implemented, maybe I can hook into the labels somehow
