# Gadfly: how to add bar spacing to stacked plot without shifting off center?

**URL:** <https://discourse.julialang.org/t/gadfly-how-to-add-bar-spacing-to-stacked-plot-without-shifting-off-center/62148>\
**Category:** Visualization\
**Tags:** question, gadfly\
**Created:** [May 31, 2021, 5:04pm UTC](https://discourse.julialang.org/t/gadfly-how-to-add-bar-spacing-to-stacked-plot-without-shifting-off-center/62148 "2021-05-31T17:04:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alrichar112](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alrichar112/32/25673_2.png) [@alrichar112](https://discourse.julialang.org/u/alrichar112)\
**Post date:** [May 31, 2021, 5:04pm UTC](https://discourse.julialang.org/t/gadfly-how-to-add-bar-spacing-to-stacked-plot-without-shifting-off-center/62148/1 "2021-05-31T17:04:34Z")

</div>

I’m having trouble adding bar spacing to a stacked plot, as it is shifting the bars off center.

```julia
dfsample = CSV.read("dfsample.csv", DataFrame)
p = plot(dfsample,
    x=:Percent,
    y=:LessonName,
    color=:PassType,
    Geom.bar(orientation = :horizontal),
    Theme(
        #bar_spacing=5mm
    )
)

```

In this image you can see the DataFrame. The first plot is using the code above. When I add 5mm of bar spacing note how bars are shifted off center (plot 2). Then if I remove the color argument I get the expected behavior of centered bars with 5mm of spacing (plot 3). Any ideas?

 ![Picture1](https://global.discourse-cdn.com/julialang/original/3X/c/5/c5653ea42dc60980d465996007281dd1a41cf8a1.png)

---

<div class="post-metadata">

**Author:** ![Brinkhuis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brinkhuis/32/18752_2.png) [@Brinkhuis](https://discourse.julialang.org/u/Brinkhuis)\
**Post date:** [June 1, 2022, 7:26am UTC](https://discourse.julialang.org/t/gadfly-how-to-add-bar-spacing-to-stacked-plot-without-shifting-off-center/62148/2 "2022-06-01T07:26:20Z")

</div>

Same, here with the latest version (v1.3.4) of Gadfly. Maybe open a new issue at [Issues · GiovineItalia/Gadfly.jl · GitHub](https://github.com/GiovineItalia/Gadfly.jl/issues)

```julia
using CSV, DataFrames, Statistics, Gadfly

download("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/penguins.csv", "penguins.csv")
penguins = DataFrame(CSV.File("penguins.csv"))

set_default_plot_size(16cm, 12cm)

plot(
    combine(groupby(dropmissing(penguins), [:species, :sex]), :body_mass_g .=> mean .=> :body_mass_g),
    x = "species", 
    y = "body_mass_g", 
    color = "sex", 
    Geom.bar(orientation = :vertical),
    Theme(bar_spacing = 15mm, background_color = "white",)
)

```

 ![Screenshot 2022-06-01 at 09.21.52](https://global.discourse-cdn.com/julialang/original/3X/d/4/d4ab6dea30b287d2324df499a6ee61b5b97a94d5.png)

```julia
plot(
    combine(groupby(dropmissing(penguins), [:species, :sex]), :body_mass_g .=> mean .=> :body_mass_g),
    x = "body_mass_g", 
    y = "species", 
    color = "sex", 
    Geom.bar(orientation = :horizontal),
    Theme(bar_spacing = 15mm, background_color = "white",)
)

```

 ![Screenshot 2022-06-01 at 09.23.31](https://global.discourse-cdn.com/julialang/original/3X/7/5/75c8620b5665485849b2ce11dde243021ee54f8d.png)
