# Changing geom color in Gadfly

**URL:** <https://discourse.julialang.org/t/changing-geom-color-in-gadfly/41401>\
**Category:** Visualization\
**Created:** [June 14, 2020, 8:31pm UTC](https://discourse.julialang.org/t/changing-geom-color-in-gadfly/41401 "2020-06-14T20:31:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricChameroy](https://avatars.discourse-cdn.com/v4/letter/e/7ab992/32.png) [@EricChameroy](https://discourse.julialang.org/u/EricChameroy)\
**Post date:** [June 14, 2020, 8:31pm UTC](https://discourse.julialang.org/t/changing-geom-color-in-gadfly/41401/1 "2020-06-14T20:31:07Z")

</div>

Hi. I’m trying to change the line color in a graph I’m generating using Gadfly (in a Jupyter notebook).

```julia
p = plot(Coord.cartesian(xmin=-2, xmax=2, ymin=-2, ymax=2))
for i in 1:50
  push!(p, layer(x=d.A, y=prior_dists.α[i] .+ prior_dists.βA[i] * (d.A .- mean(d.A)), Geom.line, color=[colorant"black"]))
end
display(p)

```

The above code generates the output

```julia
Plot(...)

```

If I leave out the geom, the graph defaults to points and I get black points (likewise if I specify `Geom.point`). If I leave out color, I get lines, but in Gadfly’s default color.

Am I doing something wrong?

Thanks.

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [June 14, 2020, 9:01pm UTC](https://discourse.julialang.org/t/changing-geom-color-in-gadfly/41401/2 "2020-06-14T21:01:06Z")

</div>

`Geom.line` is one geometry which still uses the syntax  
`layer(..., Geom.line, Theme(default_color="black"))` to change line color. I’m currently working on new code which will allow for the syntax `color=[colorant"black"]` with `Geom.line`. 😀

---

<div class="post-metadata">

**Author:** ![EricChameroy](https://avatars.discourse-cdn.com/v4/letter/e/7ab992/32.png) [@EricChameroy](https://discourse.julialang.org/u/EricChameroy)\
**Post date:** [June 15, 2020, 7:04pm UTC](https://discourse.julialang.org/t/changing-geom-color-in-gadfly/41401/3 "2020-06-15T19:04:41Z")

</div>

OK. Thanks.

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [June 28, 2020, 7:14pm UTC](https://discourse.julialang.org/t/changing-geom-color-in-gadfly/41401/4 "2020-06-28T19:14:50Z")

</div>

This is now available on Gadfly master (in julia: `]add Gadfly#master`). See the [Aesthetics](http://gadflyjl.org/dev/tutorial/#Aesthetics-1) section in the Gadfly docs. For your plot, you could also use [wide-form syntax](http://gadflyjl.org/dev/man/plotting/#Wide-formatted-data-1).

```julia
Y = [cumsum(randn(20)) for _ in 1:50]
x = repeat([1:20;], outer=50)
plot(Y, x=x, y=Col.value, group=Col.index, color=[colorant"black"], Geom.line)

```

![array_of_arrays](https://global.discourse-cdn.com/julialang/original/3X/1/b/1b1860e7da03df3e8f24f7da0c2c057f4d5aa5cf.png)

---

<div class="post-metadata">

**Author:** ![EricChameroy](https://avatars.discourse-cdn.com/v4/letter/e/7ab992/32.png) [@EricChameroy](https://discourse.julialang.org/u/EricChameroy)\
**Post date:** [June 29, 2020, 7:52pm UTC](https://discourse.julialang.org/t/changing-geom-color-in-gadfly/41401/5 "2020-06-29T19:52:20Z")

</div>

Thank you for the update. Will this be eventually replacing the use of `Theme()` or will both options be available?

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [June 29, 2020, 8:50pm UTC](https://discourse.julialang.org/t/changing-geom-color-in-gadfly/41401/6 "2020-06-29T20:50:24Z")

</div>

`Theme()` can be inside or outside layers (outside is the overall plot Theme).

Inside layers, Theme will still be useful for some geoms e.g. `layer(..., Geom.line, Theme(line_width=2pt))`, until those attributes are developed into proper aesthetics e.g. `layer(..., linewidth=[2pt], Geom.line) `.

---

<div class="post-metadata">

**Author:** ![EricChameroy](https://avatars.discourse-cdn.com/v4/letter/e/7ab992/32.png) [@EricChameroy](https://discourse.julialang.org/u/EricChameroy)\
**Post date:** [June 30, 2020, 9:10pm UTC](https://discourse.julialang.org/t/changing-geom-color-in-gadfly/41401/7 "2020-06-30T21:10:34Z")

</div>

Sounds good. I like using `Theme()` to set styles that will be applied to the graph as a whole and then using something like `color=[]` to style individual geoms.

Thanks for all of your work. I really like the package and I’m always looking forward to future developments.
