# How can I draw 2 series in the same chart

**URL:** https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736
**Category:** New to Julia
**Created:** [October 10, 2019, 4:08pm UTC](https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736 "2019-10-10T16:08:49Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![hasanOryx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hasanoryx/32/5373_2.png) [@hasanOryx](https://discourse.julialang.org/u/hasanOryx)
#### Post date: [October 10, 2019, 4:08pm UTC](https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736/1 "2019-10-10T16:08:49Z")

</div>

I was able to plt the first series as:

```julia
using Gadfly

history = [30,21,29,31,40,48,53,47,37,39,31,29,17,9,20,24,27,35,41,38,
          27,31,27,26,21,13,21,18,33,35,40,36,22,24,21,20,17,14,17,19,
          26,29,40,31,20,24,18,26,17,9,17,21,28,32,46,33,23,28,22,27,
          18,8,17,21,31,34,44,38,31,30,26,32];

plot(y=history, Geom.line)

```

Now I’ve another series as:

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

 ![hw05](https://global.discourse-cdn.com/julialang/original/2X/1/12ed0e9225e9b221cf2d82e8cde6a551231c02fe.png)

---

<div class="post-metadata">

### Author: ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)
#### Post date: [October 10, 2019, 4:52pm UTC](https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736/2 "2019-10-10T16:52:29Z")

</div>

A basic example:

```julia
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)

```

---

<div class="post-metadata">

### Author: ![hasanOryx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hasanoryx/32/5373_2.png) [@hasanOryx](https://discourse.julialang.org/u/hasanOryx)
#### Post date: [October 10, 2019, 5:05pm UTC](https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736/3 "2019-10-10T17:05:45Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)
#### Post date: [October 10, 2019, 5:17pm UTC](https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736/4 "2019-10-10T17:17:18Z")

</div>

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

```

---

<div class="post-metadata">

### Author: ![hasanOryx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hasanoryx/32/5373_2.png) [@hasanOryx](https://discourse.julialang.org/u/hasanOryx)
#### Post date: [October 10, 2019, 8:35pm UTC](https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736/5 "2019-10-10T20:35:06Z")

</div>

Thanks,

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

```julia
using Gadfly, DataFrames
history=[1,2,3,4,5]
forecast=[5,6,7,8,9]
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)

```

 ![31%20PM](https://global.discourse-cdn.com/julialang/original/3X/f/2/f238c362aa2d95fed34124dd2011451273743aa1.png)

---

<div class="post-metadata">

### Author: ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)
#### Post date: [October 10, 2019, 8:44pm UTC](https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736/6 "2019-10-10T20:44:08Z")

</div>

You didn’t heart my converted rust code:

> [@How can I get the chunks of a given array](https://discourse.julialang.org/t/how-can-i-get-the-chunks-of-a-given-array/29737/5):
>
> or using Statistics zx = 1.0\*reshape(series, 12, slight_smile zx .-= mean(zx, dims=1) mean(zx, dims=2)

---

<div class="post-metadata">

### Author: ![hasanOryx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hasanoryx/32/5373_2.png) [@hasanOryx](https://discourse.julialang.org/u/hasanOryx)
#### Post date: [October 10, 2019, 8:49pm UTC](https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736/7 "2019-10-10T20:49:31Z")

</div>

> [@Mattriks](#):
>
> You didn’t heart my converted rust code

🙂 was giving priority for the plotting 🙂  
Appreciate your efforts with me

---

<div class="post-metadata">

### Author: ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)
#### Post date: [October 10, 2019, 8:53pm UTC](https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736/8 "2019-10-10T20:53:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![hasanOryx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hasanoryx/32/5373_2.png) [@hasanOryx](https://discourse.julialang.org/u/hasanOryx)
#### Post date: [October 10, 2019, 8:57pm UTC](https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736/9 "2019-10-10T20:57:52Z")

</div>

> [@Mattriks](#):
>
> gold line starts at point time=6.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]`

---

<div class="post-metadata">

### Author: ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)
#### Post date: [October 10, 2019, 8:59pm UTC](https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736/10 "2019-10-10T20:59:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![hasanOryx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hasanoryx/32/5373_2.png) [@hasanOryx](https://discourse.julialang.org/u/hasanOryx)
#### Post date: [October 10, 2019, 9:04pm UTC](https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736/11 "2019-10-10T21:04:01Z")

</div>

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`

---

<div class="post-metadata">

### Author: ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)
#### Post date: [October 10, 2019, 9:32pm UTC](https://discourse.julialang.org/t/how-can-i-draw-2-series-in-the-same-chart/29736/12 "2019-10-10T21:32:41Z")

</div>

See the gadfly docs: [Scale.color\_discrete\_manual](http://gadflyjl.org/dev/gallery/scales/#%5BScale.color_discrete_manual%5D(@ref)-1)  
The [tutorial](http://gadflyjl.org/dev/tutorial/) is also useful if you want to learn “the grammar of graphics”
