# Gadfly: How to change width and opacity of lines in Geom.density?

**URL:** <https://discourse.julialang.org/t/gadfly-how-to-change-width-and-opacity-of-lines-in-geom-density/37823>\
**Category:** Visualization\
**Tags:** plotting, gadfly, visualization, plots\
**Created:** [April 18, 2020, 9:37pm UTC](https://discourse.julialang.org/t/gadfly-how-to-change-width-and-opacity-of-lines-in-geom-density/37823 "2020-04-18T21:37:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [April 18, 2020, 9:37pm UTC](https://discourse.julialang.org/t/gadfly-how-to-change-width-and-opacity-of-lines-in-geom-density/37823/1 "2020-04-18T21:37:05Z")

</div>

I tried `Theme(alphas = [0.3], line_width=10cm)`, but it didn’t work.

---

<div class="post-metadata">

**Author:** ![evanfields](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evanfields/32/1744_2.png) [@evanfields](https://discourse.julialang.org/u/evanfields)\
**Post date:** [April 18, 2020, 9:53pm UTC](https://discourse.julialang.org/t/gadfly-how-to-change-width-and-opacity-of-lines-in-geom-density/37823/2 "2020-04-18T21:53:54Z")

</div>

Setting the line width like that should work. Try using `style` in the plot command? For transparency, I’m not sure what the `alphas` option does. You could try setting the line color to something with transparency, like so:

```julia
julia> x = rand(10)
julia> using Colors
julia> plot(x = x, Geom.density, style(line_width=3mm, default_color = RGBA(.1, .1, .9, .3)))

```

 ![gadfly](https://global.discourse-cdn.com/julialang/original/3X/0/9/0904ead40b989ff72a4ab0cc26beff05aa6caa17.png)

---

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [April 19, 2020, 12:28am UTC](https://discourse.julialang.org/t/gadfly-how-to-change-width-and-opacity-of-lines-in-geom-density/37823/3 "2020-04-19T00:28:10Z")

</div>

> [@evanfields](#):
>
> style(line\_width=3mm, default\_color = RGBA(.1, .1, .9, .3))

You’re right, this works. My problem was with layering, it seems. Still, it’s weird why setting the alpha this way doesn’t work:

```julia
p = plot(
    layer(
        x = g1,
        Geom.density(bandwidth = 1),
        color = [RGBA(1, 0, 0, 0.3)], # ALPHA ignored
        style(line_width=2mm,
         ),
    ),
    layer(
        x = v1,
        Geom.density(bandwidth = 1),
         color = [RGB(0, 1, 0)],
        style(line_width=2mm),
    ),
);

```

---

<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:** [April 19, 2020, 12:46am UTC](https://discourse.julialang.org/t/gadfly-how-to-change-width-and-opacity-of-lines-in-geom-density/37823/4 "2020-04-19T00:46:36Z")

</div>

`Theme(alphas= )` is the alpha palette for the `alpha` aesthetic and `Scale.alpha_discrete` ([see Gadfly Tutorial](http://gadflyjl.org/stable/tutorial/#Discrete-Scales-1)). `alpha` and `color` are separate aesthetics, which is why `a` is ignored in `color=[RGBA(r,g,b,a)]`.  
Currently, the alpha aesthetic been enabled for `Geom.point`, `Geom.polygon`, and `Geom.ribbon`, but not `Geom.line`.

There is also `Theme(lowlight_color= )`, which is old pre-`alpha` code. This was enabled for `Geom.polygon` and `Geom.ribbon` and controls stroke color `(fill=false)` or fill color `(fill=true)`. It must be a function, e.g.

```julia
using Colors
gp = Geom.polygon(preserve_order=true)
p = plot(x=rand(20), Stat.density, gp,
# Theme(lowlight_color=x->"gray", line_width=3pt)
    Theme(lowlight_color=x->RGBA(x,0.3), line_width=3pt)
)

```

More examples of [`Stat.density`](http://gadflyjl.org/stable/gallery/statistics/#%5BStat.density%5D(@ref)-1) and [`Scale.alpha_`](http://gadflyjl.org/stable/gallery/scales/#%5BScale.alpha_continuous%5D(@ref)-1).

---

<div class="post-metadata">

**Author:** ![cscherrer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cscherrer/32/7631_2.png) [@cscherrer](https://discourse.julialang.org/u/cscherrer)\
**Post date:** [April 16, 2021, 2:48pm UTC](https://discourse.julialang.org/t/gadfly-how-to-change-width-and-opacity-of-lines-in-geom-density/37823/5 "2021-04-16T14:48:07Z")

</div>

Is there an example somewhere of transparency with `Geom.line`? I need it for plots like this:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/3/b32d8c58206a4585b62310ebf1d91db4ae408f81.jpeg)

---

<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:** [April 16, 2021, 5:17pm UTC](https://discourse.julialang.org/t/gadfly-how-to-change-width-and-opacity-of-lines-in-geom-density/37823/6 "2021-04-16T17:17:08Z")

</div>

Like this:

```julia
x = [25:55;]
n = 30
ys = [exp.([ones(length(x)) x]*rand(b)) for _ in 1:n]

plot(layer(D, x=:x, y=:y, Geom.point, color=[colorant"orange"], size=[4pt]),
    layer(ys, x=repeat(x, outer=n), y=Col.value, Geom.line, group=Col.index, 
        Theme(default_color=RGBA(0,0,0,0.1), line_width=3pt)),
    Coord.cartesian(xmin=25, xmax=55))

```

![price_quantity](https://global.discourse-cdn.com/julialang/original/3X/9/6/960434111eaa89f1a05cb3c87cc3d87eba8c1dc9.png)
