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

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
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:


can someone please give me some advices about it? Any other useful packages can draw the grouped bar chart will be helpful, thanks!!

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

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.

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)


thanks in advance!!

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

2 Likes

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

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")
1 Like

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.

plot(x,y;group=z)
1 Like

hey! nice work with those docs!

3 Likes

Inspired from your (and similar) examples :slight_smile:

3 Likes