How to draw Gantt chart using Plots

Hello,

I want to draw Gantt chart (someone told it broken bar chart) to represent a task timeline like below.
But I cannot find any information how to draw this chart using Plots.

Is there any way to draw this kind of chart using Plots?

Did you try the search bar: Search results for 'gantt' - JuliaLang

1 Like

Take a look at VegaLite.jl, and the bar chart examples, it might be possible to do it that way: http://fredo-dedup.github.io/VegaLite.jl/stable/examples/examples_barchartshistograms.html.

There seem to be even an example:
http://fredo-dedup.github.io/VegaLite.jl/stable/examples/examples_barchartshistograms.html#Gantt-Chart-(Ranged-Bar-Marks)-1

Thank you for your replies!

Of course, I tried and see your solution using Gadfly. :slight_smile:
I just wondered there is another way to draw this using Plots.

This VegaLite looks good!

I first wanted to use Plots because it has many backend supports, but maybe I should switch to other packages.

Unfortunately Gadfly is not working with Julia 1.0 right now.
VegaLite works nicely with Julia 1.0, though.

using VegaLite

@vlplot(
    :bar,
    data={
        values=[
            {worker="1",start=1,stop=3,type="A"},
            {worker="2",start=2,stop=6,type="B"},
            {worker="3",start=3,stop=7,type="B"},
            {worker="2",start=7,stop=9,type="C"}
        ]
    },
    enc={
        y="worker:o",
        x="start:q",
        x2="stop:q",
        color={
            "type:n",
            scale={range=["#EA98D2", "#659CCA", "#000000"]}
        }
    }
)

result:

By the way, could you tell me why Plots dropped Gadfly backend support?

1 Like

For Gadfly vs Plots see here :slight_smile:

There’s a PR here for Julia 1.0 support, should be merged soon.

Actually on that link I can read “I will leave the history of Gadfly vs Plots for others to explain!”… so really it’s a bit frustrating to see so many plotting packages instead of a well-established “reference” one, like ggplot2 in R or matplotlib in python…

I disagree - the approaches taken by Plots, VegaLite and gadfly are all quite different. I prefer Plots, but others prefer the others. Im often annoyed going back to R because I find ggplot unintuitive and have to Google anytime I want to do anything. But other people really like it.

Why would it be better to force everyone into the same way of doing things?

2 Likes

Here is a slightly more concise version for VegaLite.jl:

using VegaLite, DataFrames

df = DataFrame(worker=[1,2,3,2], start=[1,2,3,7], stop=[3,6,7,9], type=["A","B","B","C"])

df |> @vlplot(
    :bar,
    y="worker:n",
    x=:start,
    x2=:stop,
    color={:type, scale={range=["#EA98D2", "#659CCA", "#000000"]}}
)
1 Like