# AoG Barplot: How to match color of a single bar to theme?

**URL:** <https://discourse.julialang.org/t/aog-barplot-how-to-match-color-of-a-single-bar-to-theme/101586>\
**Category:** General Usage\
**Tags:** question, algebraofgraphics\
**Created:** [July 13, 2023, 6:47pm UTC](https://discourse.julialang.org/t/aog-barplot-how-to-match-color-of-a-single-bar-to-theme/101586 "2023-07-13T18:47:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [July 13, 2023, 6:47pm UTC](https://discourse.julialang.org/t/aog-barplot-how-to-match-color-of-a-single-bar-to-theme/101586/1 "2023-07-13T18:47:20Z")

</div>

When I generate grouped barplots in AoG, the colors of the bars are determined by the theme. However, barplots with a single group produce grey bars.  
How can I set the bar colors to match the theme?

MWE:

```julia
using AlgebraOfGraphics, CairoMakie

df = DataFrame(x = [1,2,3], y = [1,2,3] .* 0.9, z = ["1", "2", "1"]);
set_aog_theme!();
plt1 = data(df) * mapping(:x, :y) * visual(BarPlot);
fig1 = draw(plt1)
plt2 = data(df) * mapping(:x, :y; color = :z) * visual(BarPlot);
fig2 = draw(plt2)

```

Output for fig1:

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

Output for fig2:

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

---

<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:** [July 14, 2023, 12:40am UTC](https://discourse.julialang.org/t/aog-barplot-how-to-match-color-of-a-single-bar-to-theme/101586/2 "2023-07-14T00:40:26Z")

</div>

Oh, do you mean that you would like each bar to be the next color in the default color palette? If so, I guess we could map on `:x` then feed to [`verbatim`](https://aog.makie.org/stable/API/functions/#AlgebraOfGraphics.verbatim) to suppress the colorbar,

```julia
using CairoMakie, AlgebraOfGraphics

x = [1, 2, 3]
y = x .* 0.9
df = (; x, y)

plt = data(df) * mapping(:x, :y; color=:x => verbatim) * visual(BarPlot)
draw(plt)

```

or just set the color visually

```julia
plt = data(df) * mapping(:x, :y) * visual(BarPlot; color=x)
draw(plt)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/8/18a10fda6afe1e66f27108994d4157d59d1f9d53.png)

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [July 14, 2023, 1:07am UTC](https://discourse.julialang.org/t/aog-barplot-how-to-match-color-of-a-single-bar-to-theme/101586/3 "2023-07-14T01:07:32Z")

</div>

Thanks, but my issue is with the plot without the color mapping. When I plot a single series, the bars are grey. That clashes with all the other bar graphs where the colors come from the theme.

So, I’m trying to replace the grey color in fig1 (in my example) with the first color from fig2.

---

<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:** [July 14, 2023, 4:38am UTC](https://discourse.julialang.org/t/aog-barplot-how-to-match-color-of-a-single-bar-to-theme/101586/4 "2023-07-14T04:38:27Z")

</div>

Ah, do you mean like this equivalent in vanilla Makie with [Cycled](https://docs.makie.org/stable/documentation/theming/index.html#manual_cycling_using_cycled)?

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

barplot!(ax, x, y; color=Cycled(1))

fig

```

It looks like there is currently an [open issue](https://github.com/MakieOrg/Makie.jl/issues/2893) that would allow this to work in AoG I think, for example with `visual(BarPlot; color=Cycled(1))`. In the meantime, could using the default color palette directly be a workaround?

```julia
set_aog_theme!()

plt = data(df) * mapping(:x, :y) * visual(BarPlot; color=Makie.wong_colors()[1])
draw(plt)

```

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

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [July 14, 2023, 11:25am UTC](https://discourse.julialang.org/t/aog-barplot-how-to-match-color-of-a-single-bar-to-theme/101586/5 "2023-07-14T11:25:59Z")

</div>

Thank you - that works.

And just to finish up: to match the single bar color with the first bar color of the theme:

```julia
thm = AlgebraOfGraphics.aog_theme();
barColors = first(thm.palette);
# and in the plot
visual(BarPlot; color = first(barColors))

```
