# Make transparent square in Gadfly

**URL:** https://discourse.julialang.org/t/make-transparent-square-in-gadfly/54116
**Category:** Visualization
**Tags:** gadfly
**Created:** [January 28, 2021, 12:32pm UTC](https://discourse.julialang.org/t/make-transparent-square-in-gadfly/54116 "2021-01-28T12:32:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![fredih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredih/32/20945_2.png) [@fredih](https://discourse.julialang.org/u/fredih)
#### Post date: [January 28, 2021, 12:32pm UTC](https://discourse.julialang.org/t/make-transparent-square-in-gadfly/54116/1 "2021-01-28T12:32:33Z")

</div>

I want to plot a transparent square over certain time ranges in the Gantt chart @Mattriks created [here.](https://discourse.julialang.org/t/gantt-chart/6988/2)

It looks like this:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/9/f9966a6c172a6845d03a6e2407f6afbd160af0b9.png)

And I want it to look somtehing like this:  
 ![ejemplo-gadfly](https://global.discourse-cdn.com/julialang/original/3X/d/5/d5c51a6b42d808fcbc43b3af17ae6783bc329316.png)

How could I do it?

---

<div class="post-metadata">

### Author: ![Ricardo\_Rosa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ricardo_rosa/32/18564_2.png) [@Ricardo\_Rosa](https://discourse.julialang.org/u/Ricardo_Rosa)
#### Post date: [January 28, 2021, 12:43pm UTC](https://discourse.julialang.org/t/make-transparent-square-in-gadfly/54116/2 "2021-01-28T12:43:55Z")

</div>

You can add layers with `Geom.bar` and `alpha`. Like so

```julia
using DataFrames
using Dates
using Gadfly

D1 = DataFrame(y = Int[1, 2, 3, 4],
    ylab=["Collect data", "Clean data", "Analyze data", "Write report"],
    x = Date.(["2017-04-01", "2018-04-01", "2018-06-01", "2019-04-01"]),
    xend = Date.(["2018-04-01", "2018-06-01", "2019-04-01", "2020-04-01"]),
    id = ["a","b","b","c"]
)

ylabdict = Dict(i=>D1[!,:ylab][i] for i in 1:4)
coord = Coord.cartesian(ymin=0.4, ymax=4.6)

D2 = DataFrame(y=Int[5],
    xmin=Date.(["2017-01-01"]), xmax=Date.(["2017-06-01"])
)
D3 = DataFrame(y=Int[5],
    xmin=Date.(["2018-06-01"]), xmax=Date.(["2018-12-31"])
)

l2 = layer(D2, xmin=:xmin, xmax=:xmax, y=:y, Geom.bar, alpha=[0.2], Theme(default_color="white"), order=1)
l3 = layer(D3, xmin=:xmin, xmax=:xmax, y=:y, Geom.bar, alpha=[0.2], Theme(default_color="white"), order=1)

p = plot(D1, coord, 
    layer(x=:x, xend=:xend, y=:y, yend=:y, color=:id, Geom.segment, Theme(line_width=10mm)), 
    Scale.y_continuous(labels=i->get(ylabdict,i,"")),
    Guide.xlabel("Time"), Guide.ylabel(""),
    Theme(key_position=:none), l2, l3
)

```

Then you get the following image

 ![plan_overlay](https://global.discourse-cdn.com/julialang/original/3X/0/0/006aea261fdd7ee9db6cf7ae6c64dc3b5ed51167.png)

---

<div class="post-metadata">

### Author: ![fredih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredih/32/20945_2.png) [@fredih](https://discourse.julialang.org/u/fredih)
#### Post date: [January 28, 2021, 12:56pm UTC](https://discourse.julialang.org/t/make-transparent-square-in-gadfly/54116/3 "2021-01-28T12:56:01Z")

</div>

Thanks! That’s exactly what I wanted!

---

<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: [January 28, 2021, 10:48pm UTC](https://discourse.julialang.org/t/make-transparent-square-in-gadfly/54116/4 "2021-01-28T22:48:14Z")

</div>

An update to the above code:

```julia
D1 = DataFrame(
    ylab=["Collect data", "Clean data", "Analyze data", "Write report"],
    x=Date.(["2017-04-01", "2018-04-01", "2018-06-01", "2019-04-01"]),
    xend=Date.(["2018-04-01", "2018-06-01", "2019-04-01", "2020-04-01"]),
    id=["a","b","b","c"]
)

D2 = DataFrame(xmin=Date.(["2017-01-01", "2018-06-01"]), 
    xmax=Date.(["2017-07-01", "2018-12-31"]))
l2=layer(D2, xmin=:xmin, xmax=:xmax, Geom.vband, color=[colorant"red"], alpha=[0.2])

p = plot(D1, Scale.y_discrete,
    layer(x=:x, xend=:xend, y=:ylab, yend=:ylab, color=:id, Geom.segment, 
        Theme(line_width=10mm)), l2,
    Guide.xlabel("Time"), Guide.ylabel(""), Theme(key_position=:none))

```

![Gantt](https://global.discourse-cdn.com/julialang/original/3X/c/1/c126fb0be213c3516311bb6b70109e6a6d6c0923.png)

See [Geom.band](http://gadflyjl.org/dev/gallery/geometries/#%5BGeom.band%5D(@ref),-%5BGeom.hband%5D(@ref),-%5BGeom.vband%5D(@ref)) in the Gadfly docs

---

<div class="post-metadata">

### Author: ![fredih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredih/32/20945_2.png) [@fredih](https://discourse.julialang.org/u/fredih)
#### Post date: [January 29, 2021, 12:54pm UTC](https://discourse.julialang.org/t/make-transparent-square-in-gadfly/54116/5 "2021-01-29T12:54:07Z")

</div>

Great! Thanks!
