# How to draw the grouped bar plot in julia(best using Vegalite)

**URL:** <https://discourse.julialang.org/t/how-to-draw-the-grouped-bar-plot-in-julia-best-using-vegalite/89659>\
**Category:** Visualization\
**Tags:** question, plotlyjs, vegalite\
**Created:** [November 2, 2022, 1:09pm UTC](https://discourse.julialang.org/t/how-to-draw-the-grouped-bar-plot-in-julia-best-using-vegalite/89659 "2022-11-02T13:09:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![akshdfyehd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/akshdfyehd/32/39097_2.png) [@akshdfyehd](https://discourse.julialang.org/u/akshdfyehd)\
**Post date:** [November 2, 2022, 1:09pm UTC](https://discourse.julialang.org/t/how-to-draw-the-grouped-bar-plot-in-julia-best-using-vegalite/89659/1 "2022-11-02T13:09:50Z")

</div>

Hi, I need to draw a graph which is grouped bar chart, y axis will be salary, x axis will be job title, and I want to present each job title with employment type in different colors(this contains part time, full time, freelance, contract these four types), it will be graph like this:  
 ![1667394740089](https://global.discourse-cdn.com/julialang/original/3X/5/f/5f5d83ef71bf4854c2d70b3d80ec83873812c4c4.png)  
but the final graph needs to be horizontal bar plot as there are lots of job title in my dataset.

I have tried vegalite package but I found the code for grouped bar chart is complex to understand, therefore I have looked at plotlyjs, but I got the error:

 ![1667393994877](https://global.discourse-cdn.com/julialang/original/3X/6/8/68ac237264455a60117a3799854f080ce439aa9b.png)  
can someone please give me some advices about it? Any other useful packages can draw the grouped bar chart will be helpful, thanks!!

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [November 2, 2022, 4:38pm UTC](https://discourse.julialang.org/t/how-to-draw-the-grouped-bar-plot-in-julia-best-using-vegalite/89659/2 "2022-11-02T16:38:20Z")

</div>

I can’t try this myself, but the follwong might work:

```julia
using DataFrames, PlotlyJS, InMemoryDatasets
df = DataFrame(ds)
plot(df, x=:job_title, y =:salary_in_usd, color=:employment_type, kind = "bar")

```

The api of Plotly does not accept InMemoryDatasets. Hence you need to convert it to a DataFrame first.

---

<div class="post-metadata">

**Author:** ![akshdfyehd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/akshdfyehd/32/39097_2.png) [@akshdfyehd](https://discourse.julialang.org/u/akshdfyehd)\
**Post date:** [November 2, 2022, 4:45pm UTC](https://discourse.julialang.org/t/how-to-draw-the-grouped-bar-plot-in-julia-best-using-vegalite/89659/3 "2022-11-02T16:45:50Z")

</div>

Hi, thanks for the reply!  
yes I realized that and I have turned ds into dataframe but there are still same errors, I have decided to avoid this problem by use the filter function from IMD package and draw the graph one by one, oh by the way, do you know how to extract all the rows that have employment type is FT from this dataset? (use the filter function from IMD package)

 ![1667407510825](https://global.discourse-cdn.com/julialang/original/3X/1/3/13a16b1c2d2dc6ee7958ed72d3fb61b2b552e8d4.png)  
thanks in advance!!

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 2, 2022, 4:49pm UTC](https://discourse.julialang.org/t/how-to-draw-the-grouped-bar-plot-in-julia-best-using-vegalite/89659/4 "2022-11-02T16:49:09Z")

</div>

> [@akshdfyehd](#):
>
> Any other useful packages can draw the grouped bar chart will be helpful, thanks!!

I think all plotting packages can do it. GMT.jl does it with this syntax (and look) but it doesn’t accept DataFrames directly.  
[https://www.generic-mapping-tools.org/GMTjl\_doc/examples/plotting\_functions/03\_bars/#example\_13075626188285987574](https://www.generic-mapping-tools.org/GMTjl_doc/examples/plotting_functions/03_bars/#example_13075626188285987574)

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [November 2, 2022, 5:02pm UTC](https://discourse.julialang.org/t/how-to-draw-the-grouped-bar-plot-in-julia-best-using-vegalite/89659/5 "2022-11-02T17:02:59Z")

</div>

Sorry, I don’t have experience with InMemoryDatasets, but the following works for me

```julia
using DataFrames, PlotlyJS
df = DataFrame(a=[1,1,2,3,2], b = ["a","a","b","c","c"], c = rand(5))
plot(df, x = :a, y = :c, color= :b, kind = "bar")

```

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [November 2, 2022, 6:16pm UTC](https://discourse.julialang.org/t/how-to-draw-the-grouped-bar-plot-in-julia-best-using-vegalite/89659/6 "2022-11-02T18:16:15Z")

</div>

Of course everyone has different opinions, but just would like to mention that i think group bar plots are difficult to read and almost always better as line plots. It’s worth considering.

```julia
plot(x,y;group=z)

```

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [November 2, 2022, 6:16pm UTC](https://discourse.julialang.org/t/how-to-draw-the-grouped-bar-plot-in-julia-best-using-vegalite/89659/7 "2022-11-02T18:16:17Z")

</div>

hey! nice work with those docs!

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 2, 2022, 6:20pm UTC](https://discourse.julialang.org/t/how-to-draw-the-grouped-bar-plot-in-julia-best-using-vegalite/89659/8 "2022-11-02T18:20:01Z")

</div>

Inspired from your (and similar) examples 🙂
