# Change color of specific bar in a bar plot

**URL:** https://discourse.julialang.org/t/change-color-of-specific-bar-in-a-bar-plot/67459
**Category:** New to Julia
**Tags:** visualization, makie
**Created:** [August 31, 2021, 10:13pm UTC](https://discourse.julialang.org/t/change-color-of-specific-bar-in-a-bar-plot/67459 "2021-08-31T22:13:38Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![vtomar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vtomar/32/18304_2.png) [@vtomar](https://discourse.julialang.org/u/vtomar)
#### Post date: [August 31, 2021, 10:13pm UTC](https://discourse.julialang.org/t/change-color-of-specific-bar-in-a-bar-plot/67459/1 "2021-08-31T22:13:38Z")

</div>

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`

```julia
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)

```

---

<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: [August 31, 2021, 10:32pm UTC](https://discourse.julialang.org/t/change-color-of-specific-bar-in-a-bar-plot/67459/2 "2021-08-31T22:32:24Z")

</div>

One way would be `ifelse`:

```julia
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

```

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/2/3/239581938adb2c77d7b5782cc3fa46a57c1ff9fa.png)
