# Coloring boxplot groups in Makie

Hi,

I’m discovering Makie and after reading the documentation, I don’t understand how to produce boxplots that have different colors. Here’s a MWE:

``````group = repeat([1,2],inner=500)
boxplot(rand(1:3,1000), randn(1000), dodge = group)
``````

Which produces 6 boxplots, grouped two by two, as expected. I would just like color differently the right plot of each dodge but `color = group` does not work.

Thanks

It’s because I use Makie not StatsPlots. Sorry I should have specified it in the post.

My bad you clearly said `Makie`. However, looking for examples I came across examples from `StatsPlots` and I then forgot you had specifically required `Makie`!

That gives me `DimensionMismatch("arrays could not be broadcast to a common size; got a dimension with lengths 1000 and 200")` (Makie 0.13.11).

Ha sorry I pasted the wrong group. It’s supposed to be

`group = repeat([1,2], inner=500)`

Let me fix it

So, you could use AlgebraOfGraphics to generate the correct Makie boxplot as follows.

``````julia> using AlgebraOfGraphics, CairoMakie

julia> set_aog_theme!() # optional

julia> df = (x = rand(1:3, 1000), y = rand(1000), group = rand(1:2, 1000));

julia> plt = data(df) * mapping(:x, :y, color = :group => nonnumeric, dodge = :group => nonnumeric) * visual(BoxPlot);

julia> draw(plt)
``````

Doing this plot directly with Makie is a bit clumsy at the moment, but I’m planning to make a PR to support passing a vector of colors (see examples with violin, where this is already possible).

2 Likes

Ha okay great. I did not know Algebra of Graphics. Thanks!