# AlgebraOfGraphics visual(Lines): how can I keep AoG from joining up lines corresponding to different parameter values?

**URL:** <https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661>\
**Category:** Visualization\
**Created:** [June 21, 2023, 3:08pm UTC](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661 "2023-06-21T15:08:42Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_White](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_white/32/50922_2.png) [@Christopher\_White](https://discourse.julialang.org/u/Christopher_White)\
**Post date:** [June 21, 2023, 3:08pm UTC](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661/1 "2023-06-21T15:08:42Z")

</div>

The code

```
using DataFrames
using AlgebraOfGraphics
using CairoMakie

df1 = DataFrame(x = 1:10, y = (1:10).^2, parameter = 1)
df2 = DataFrame(x = 1:10, y = 1.1*(1:10).^2, parameter = 2)
df = [df1; df2]
aogplt = data(df) * mapping(:x,:y, color=:parameter) * visual(Lines)
fg = draw(aogplt)
save("/tmp/aog-example.png", fg)

```

plots a fake dataset in which different values of `paramter` produce slightly different results. That code produces

 ![aog-example](https://global.discourse-cdn.com/julialang/original/3X/0/8/08bfa849fdd248082166248987fa64cf655d4a06.png)

The two parameter values are joined up by the straight line going back to (1,1)! How can I get rid of that line?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 21, 2023, 4:58pm UTC](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661/2 "2023-06-21T16:58:44Z")

</div>

> [@Christopher\_White](#):
>
> `color=:parameter`

Try `color = :parameter => nonnumeric`, that function signals that the column should be interpreted as categorical even though it’s numeric (that’s why you have a continuous colorbar)

---

<div class="post-metadata">

**Author:** ![Christopher\_White](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_white/32/50922_2.png) [@Christopher\_White](https://discourse.julialang.org/u/Christopher_White)\
**Post date:** [June 21, 2023, 6:46pm UTC](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661/3 "2023-06-21T18:46:42Z")

</div>

This works, but unfortunately in my application the parameter _is_ numeric, and I do want a continuous colorbar. (It’s is a simulation precision parameter that I’m tuning towards an exact calculation.)

---

<div class="post-metadata">

**Author:** ![Christopher\_White](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_white/32/50922_2.png) [@Christopher\_White](https://discourse.julialang.org/u/Christopher_White)\
**Post date:** [June 21, 2023, 7:02pm UTC](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661/4 "2023-06-21T19:02:35Z")

</div>

Maybe a better example would be this code

```
using DataFrames
using AlgebraOfGraphics
using CairoMakie

dfs = [DataFrame(x = 1:10, y = α*(1:10).^2, parameter = α) for α = 1.0:0.1:1.5]
df = Float32.(vcat(dfs...))

aogplt = data(df) * mapping(:x,:y, color= :parameter ) * visual(Lines)
fg = draw(aogplt)
save("/tmp/aog-example-colorbar.png", fg)

aogplt = data(df) * mapping(:x,:y, color= :parameter => nonnumeric) * visual(Lines)
fg = draw(aogplt)
save("/tmp/aog-example-nonnumeric.png", fg)

```

The nonnumeric plot looks like this:

 ![aog-example-nonnumeric](https://global.discourse-cdn.com/julialang/original/3X/d/d/dde3ef28080d5ed6756716f690e2aa5c293441e3.png)

---

<div class="post-metadata">

**Author:** ![Christopher\_White](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_white/32/50922_2.png) [@Christopher\_White](https://discourse.julialang.org/u/Christopher_White)\
**Post date:** [June 21, 2023, 7:03pm UTC](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661/5 "2023-06-21T19:03:36Z")

</div>

and the colorbar’d plot looks like this:

 ![aog-example-colorbar](https://global.discourse-cdn.com/julialang/original/3X/b/3/b3e3465a7c478a0f5ef22fca8bb47b96bbd6cbd1.png)

(sorry for the multiple replies; per discourse I’m a new user and am only allowed to upload one image per post)

---

<div class="post-metadata">

**Author:** ![karlroyen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karlroyen/32/9301_2.png) [@karlroyen](https://discourse.julialang.org/u/karlroyen)\
**Post date:** [June 22, 2023, 4:48am UTC](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661/6 "2023-06-22T04:48:41Z")

</div>

You can add `NaN` to the end of the data for each line:

```julia
dfs = [DataFrame(x = [1:10; Inf], y = [α*(1:10).^2; NaN], parameter = α) for α = 1.0:0.1:1.5]

```

 ![aog-example-colorbar](https://global.discourse-cdn.com/julialang/original/3X/2/8/286a787f93edf0ef6bb0d117b19c37017a1f29e8.png)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 22, 2023, 5:47am UTC](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661/7 "2023-06-22T05:47:37Z")

</div>

You can use `group = :columnname` where that column splits the data into groups while leaving color etc. intact. In your example you’d reuse the color column

---

<div class="post-metadata">

**Author:** ![karlroyen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karlroyen/32/9301_2.png) [@karlroyen](https://discourse.julialang.org/u/karlroyen)\
**Post date:** [June 22, 2023, 7:09am UTC](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661/8 "2023-06-22T07:09:14Z")

</div>

Ah, nice, I did not know about that option! That is much easier 🙂 .

---

<div class="post-metadata">

**Author:** ![Christopher\_White](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_white/32/50922_2.png) [@Christopher\_White](https://discourse.julialang.org/u/Christopher_White)\
**Post date:** [June 22, 2023, 10:05am UTC](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661/9 "2023-06-22T10:05:10Z")

</div>

This isn’t working for me:

```
using DataFrames
using AlgebraOfGraphics
using CairoMakie

dfs = [DataFrame(x = 1:10, y = α*(1:10).^2, parameter = α) for α = 1.0:0.1:1.5]
df = Float32.(vcat(dfs...))

aogplt = data(df) * mapping(:x,:y, color = :parameter, group=:parameter) * visual(Lines)
fg = draw(aogplt)
save("/tmp/aog-example-group.png", fg)

```

gives

 ![aog-example-colorbar](https://global.discourse-cdn.com/julialang/original/3X/b/3/b3e3465a7c478a0f5ef22fca8bb47b96bbd6cbd1.png)

Are there docs I can read on this `group` argument? (I’m on AoG v0.6.16, FWIW.)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 22, 2023, 11:28am UTC](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661/10 "2023-06-22T11:28:49Z")

</div>

Maybe you need `group = :parameter => nonnumeric`? Not sure why it wouldn’t work otherwise, that `group` setting is used in the tutorial even.

---

<div class="post-metadata">

**Author:** ![devel-chm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devel-chm/32/3572_2.png) [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Post date:** [June 22, 2023, 1:47pm UTC](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661/11 "2023-06-22T13:47:47Z")

</div>

Did you try this by karlroyen?

> [@AlgebraOfGraphics visual(Lines): how can I keep AoG from joining up lines corresponding to different parameter values?](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661/6):
>
> You can add NaN to the end of the data for each line: dfs = [DataFrame(x = [1:10; Inf], y = [α\*(1:10).^2; NaN], parameter = α) for α = 1.0:0.1:1.5]

---

<div class="post-metadata">

**Author:** ![Christopher\_White](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_white/32/50922_2.png) [@Christopher\_White](https://discourse.julialang.org/u/Christopher_White)\
**Post date:** [June 22, 2023, 3:18pm UTC](https://discourse.julialang.org/t/algebraofgraphics-visual-lines-how-can-i-keep-aog-from-joining-up-lines-corresponding-to-different-parameter-values/100661/12 "2023-06-22T15:18:44Z")

</div>

I missed that under Jules’ reply. That does indeed work—thanks for nudging me about it, and thanks to @karlroyen .

@jules—indeed, `group = :parameter => nonnumeric` does it. I think that’s the solution.
