# Adding Guide.manual\_color\_key to Geom.ribbon plot with hex codes

**URL:** <https://discourse.julialang.org/t/adding-guide-manual-color-key-to-geom-ribbon-plot-with-hex-codes/77281>\
**Category:** General Usage\
**Tags:** question, gadfly, plots\
**Created:** [March 2, 2022, 9:11am UTC](https://discourse.julialang.org/t/adding-guide-manual-color-key-to-geom-ribbon-plot-with-hex-codes/77281 "2022-03-02T09:11:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![colebrookson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colebrookson/32/19567_2.png) [@colebrookson](https://discourse.julialang.org/u/colebrookson)\
**Post date:** [March 2, 2022, 9:11am UTC](https://discourse.julialang.org/t/adding-guide-manual-color-key-to-geom-ribbon-plot-with-hex-codes/77281/1 "2022-03-02T09:11:58Z")

</div>

I’m assuming I’m just missing something, but I can’t find how to do this in the docs.

Say I have a plot from the following data

```julia
using DataFrames, Gadfly, Distributions

# make some data 
x = range(0, 2π, length=100)
y1 = @. sin(x) + 0.01 * randn()
y2 = @. cos(x) + 0.01 * randn()
x = vcat(x,x)
y = vcat(y1,y2)
# string-based categorical variable 
func = vcat(repeat(["sin"], 100), repeat(["cos"], 100))

# make dataframe 
df = DataFrame(
    hcat(x,y,func),
    [:x,:y,:func]
)
df[!, 1] = convert.(Float64, df[:, 1]) # there's probably a better way to do this....
df[!, 2] = convert.(Float64, df[:, 2])
df[!, 3] = convert.(String, df[:, 3])

# add the upper and lower bounds for the ribbon 
df.ymax = df.y .+ rand(Uniform(0.3,0.7), 200)
df.ymin = df.y .- rand(Uniform(0.3,0.7), 200)

```

And I want to plot a line with a ribbon. I can do that no problem with this:

```julia
plot(df, x=:x,y=:y,
        ymax = :ymax, ymin = :ymin, alpha = [0.2],
        color = :func,
        Geom.line, Geom.ribbon)

```

which produces this:

 ![Screenshot from 2022-03-02 04-06-56](https://global.discourse-cdn.com/julialang/original/3X/9/9/994ba6c60187d2cac9bf8d44b887410d01502b09.png)

But I want to specify which colors to use, which I think I am supposed to do via the `Guide.manual_color_key`, and that would ideally also let me rename the legend items, so I figured it would work something like this

```julia
plot(df, x=:x,y=:y,
        ymax = :ymax, ymin = :ymin, alpha = [0.2],
        color = :func,
        Geom.line, Geom.ribbon,
        Guide.manual_color_key("Function",["sin","cos"],
                                 ["#3b3759", "#cf8da7"]))

```

but that produces this:

 ![Screenshot from 2022-03-02 04-10-20](https://global.discourse-cdn.com/julialang/original/3X/3/5/35510409885799d0c887392fd21b5163d7ab525d.png)

I want both the ribbons and the lines to reflect the specified colors - how should I re-state that?

---

<div class="post-metadata">

**Author:** ![colebrookson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colebrookson/32/19567_2.png) [@colebrookson](https://discourse.julialang.org/u/colebrookson)\
**Post date:** [March 2, 2022, 10:29am UTC](https://discourse.julialang.org/t/adding-guide-manual-color-key-to-geom-ribbon-plot-with-hex-codes/77281/2 "2022-03-02T10:29:40Z")

</div>

Okay actually I figured it out! It wasn’t `Guide.manual_color_key` I wanted, but instead `Scale.color_discrete_manual`! Apologies for my slander to the package authors, it was in fact in the docs (as it always is) I just hadn’t found it yet!!

The solution:

```julia
plot(df, x=:x,y=:y,
        ymax = :ymax, ymin = :ymin, alpha = [0.2],
        color = :func,
        Geom.line, Geom.ribbon,
        Guide.colorkey(title="Function",labels=["Sin","Cos"]),
        Scale.color_discrete_manual("#3b3759", "#cf8da7"))

```

Which produces exactly what I wanted 🙂

 ![Screenshot from 2022-03-02 05-29-10](https://global.discourse-cdn.com/julialang/original/3X/8/f/8fbcdc0663d72fc6199a5ca37eddf8c4fd771d25.png)
