How can I draw 2 series in the same chart

I was able to plt the first series as:

using Gadfly

history = [30,21,29,31,40,48,53,47,37,39,31,29,17,9,20,24,27,35,41,38,

plot(y=history, Geom.line)

Now I’ve another series as:

forecast = [28, 30, 19, 45]

In the same chart I want to draw the second series as a continuity of the first series, but with different line colors, something like:

A basic example:

labels = vcat(fill.(["series","forecast"], [90,10])...)
df = DataFrame(time=1:100, y=cumsum(randn(100)), id=labels)
p = plot(df, x=:time, y=:y, Geom.line, color=:id)

Did not get where and how shall I use my series actual data or actual names?

labels = vcat(fill.(["history", "forecast"], [72, 4])...)
df = DataFrame(time=1:76, y=vcat(history, forecast), id=labels)

1 Like


But what if the first point of the second series is the last point of the first series, how can I connect them together, in the example beow, I need both lines to be connected to point number 5, and both lines connected together at this point, as you see below there is a gap, how can I get rid of this gap and connect the lines together at point 5

using Gadfly, DataFrames
labels = vcat(fill.(["history", "forecast"], [5, 5])...)
df = DataFrame(time=1:10, y=vcat(history, forecast), id=labels)
p = plot(df, x=:time, y=:y, Geom.line, color=:id)

You didn’t heart my converted rust code:

:slight_smile: was giving priority for the plotting :slight_smile:
Appreciate your efforts with me

In the above example plot, you need to start the gold line at time=5.0. Currently in the dataframe, the gold line starts at point time=6.0. i.e. both the history and forecast need a point at time=5.0

It starts at point 6 in the plot, but in the array itself it starts at point 5 forecast=[5,6,7,8,9]

so in the DataFrame, time=vcat(1:5,5:9)

1 Like

Thanks, mm, hope this to be the last for this point, how can I select the line color my self for each series, instead of color=:id

See the gadfly docs: Scale.color_discrete_manual
The tutorial is also useful if you want to learn “the grammar of graphics”

1 Like