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

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

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

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)

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.)

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:

and the colorbar’d plot looks like this:

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

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]

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

2 Likes

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

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

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

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

1 Like

Did you try this by karlroyen?

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.