# Plotting a grouped bar chart in Gnuplot.jl

**URL:** <https://discourse.julialang.org/t/plotting-a-grouped-bar-chart-in-gnuplot-jl/52671>\
**Category:** General Usage\
**Created:** [December 31, 2020, 9:01pm UTC](https://discourse.julialang.org/t/plotting-a-grouped-bar-chart-in-gnuplot-jl/52671 "2020-12-31T21:01:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [December 31, 2020, 9:01pm UTC](https://discourse.julialang.org/t/plotting-a-grouped-bar-chart-in-gnuplot-jl/52671/1 "2020-12-31T21:01:04Z")

</div>

pinging @gcalderone

I am trying to create a grouped bar chart. Something like [Clustered bar plot in gnuplot - Stack Overflow](https://stackoverflow.com/questions/5130517/clustered-bar-plot-in-gnuplot) or [Gnuplot documentation (bersch.net)](http://www.bersch.net/gnuplot-doc/histograms.html) but I am not getting anywhere.

I have so far

```julia
 @gp "reset"
    @gp :- "set key left"
    @gp :- "set style data histogram"
    @gp :- "set style histogram cluster"
    @gp :- "set style fill solid border rgb 'black"
    #@gp :- "set auto x"
    #@gp :- "set yrange [0:*]"
    @gp :- "using $(dda[:, 1]) title 'hello'" #lw 2 dt 1 lc rgb 'black'
    #@gp :- [22, 22, 22] dda[:, 2] "title 'hello'" #lw 2 dt 1 lc rgb 'black'
    @gp

```

where `dda` is

```julia
julia> dda
3×4 Adjoint{Float64,Array{Float64,2}}:
 0.444444 3.77778 7.382 20.7153
 0.466667 3.96667 7.74938 21.7494
 0.511111 4.34444 8.44978 23.7831

```

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [December 31, 2020, 9:37pm UTC](https://discourse.julialang.org/t/plotting-a-grouped-bar-chart-in-gnuplot-jl/52671/2 "2020-12-31T21:37:49Z")

</div>

I was able to figure out a solution. There are a few factors at play. First, when using `set style data histogram` it only expects one column for the plotting command. Second, the natural `x` tic values start at 0 and increment by 1.

So we simply have to simply add each column 1 by 1.

```julia
 @gp "reset"
    @gp :- "set key left"
    @gp :- "set style data histogram"
    @gp :- "set style histogram cluster gap 1"
    @gp :- "set style fill solid border rgb 'black"
    @gp :- "set auto x"
    #@gp :- "set yrange [0:*]"
    @gp :- dda[:, 1] "title '30 days'" #lw 2 dt 1 lc rgb 'black'
    @gp :- dda[:, 2] "title '45 days'" #lw 2 dt 1 lc rgb 'black'
    @gp :- dda[:, 3] "title '90 days'" #lw 2 dt 1 lc rgb 'black'
    @gp :- dda[:, 4] "title '150 days'" #lw 2 dt 1 lc rgb 'black'
    @gp

```

For the x labels, if using gnuplot script, one can say `plot for [COL=2:4:2] 'file.dat' using COL:xticlabels(1)` where the x-axis label is then calculated from the first column of the data file. But given that we are in Julia code, I am not sure how to write the equivalent. Instead, a solution is to replace the xtic values manually.

```julia
 @gp :- "set xtics $xticvals" 

```

where `xticvals = ("label 1" 0, "label 2", 1"...)`
