# Assigning a color to each variable

**URL:** https://discourse.julialang.org/t/assigning-a-color-to-each-variable/77967
**Category:** General Usage
**Tags:** plotting, plots
**Created:** [March 16, 2022, 12:56pm UTC](https://discourse.julialang.org/t/assigning-a-color-to-each-variable/77967 "2022-03-16T12:56:06Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Juan\_Mac\_Donagh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan_mac_donagh/32/31798_2.png) [@Juan\_Mac\_Donagh](https://discourse.julialang.org/u/Juan_Mac_Donagh)
#### Post date: [March 16, 2022, 12:56pm UTC](https://discourse.julialang.org/t/assigning-a-color-to-each-variable/77967/1 "2022-03-16T12:56:06Z")

</div>

Hi, I was wondering if there was a way of automatically assigning a color to each bar when doing a bar plot (Plots.bar), something similar to color=:variable in Gadfly.  
My data looks like this:

| Var1 | Var2 | Var3 |
| --- | --- | --- |
| 1 | 0.000224135 | APR |
| 1 | 7.60581e-6 | NAPR |
| 1 | 0.0025156 | SF |
| 2 | 4.79794e-5 | APR |
| 2 | 0.00057933 | NAPR |
| 2 | 0.0051411 | SF |

This is how I would do it with Gadfly:  
figure = Gadfly.plot(  
df,  
x=:Var1,  
y=:Var2,  
color=:Var3,  
Geom.bar(position=:stack))

But I need to use Plots.  
Thanks a lot!
