Change color of specific bar in a bar plot

Below is some sample code using Makie that generates horizontal bar plots in blue color. I want to color one of the bars to be with a different color. How would I do that? The bar that needs to be colored: The y axis value of it is stored in the variable colorBar_YaxisValue

using CairoMakie
colorBar_YaxisValue = 10

f = Figure(resolution = (1000, 800))

ax = Axis(f[1, 1], title = "test", ylabel = "Prices")

barplot!(ax, 1:20, 101:120, color = :blue, direction = :x)

#lines!(ax, fill(10, 20), fill(0, 20), color = :red)

display(f)

One way would be ifelse:

colorBar_YaxisValue = 10

f = Figure(resolution = (1000, 800))

ax = Axis(f[1, 1], title = "test", ylabel = "Prices")

barplot!(ax, 1:20, 101:120,
    color = ifelse.(1:20 .== colorBar_YaxisValue, :red, :blue),
    direction = :x)

f

1 Like