Lines connecting data points don't follow order changed by sorter function (AoG)

ristretti
Thu, 17 Nov 2022 10:47:57 +0000
Visualization

Hello everyone =)
I am trying to connect data points across a categorical variable on the x axis. With the default order the points are connected as expected (with a line from 1 to 2 and a line from 2 to 3). When i change the category order on the x axis using the sorter function, the points are still connected in the default order. I would expect there to be a line from 2 to 1 and a line from 1 to 3.

using DataFrames, CairoMakie, AlgebraOfGraphics

D = DataFrame(x = repeat(["\"1\"", "\"2\"", "\"3\""], outer = 2),
                          y = rand(6),
                          group = repeat(["a", "b"], inner = 3))
  f = Figure()
  p1 = data(D) * mapping(:x, :y, color = :group) * visual(Lines)
  p2 = data(D) * mapping(:x => sorter("\"2\"", "\"1\"", "\"3\""), :y, color = :group) * visual(Lines)
  draw!(f[1,1], p1, axis = (; title = "default order"))
  draw!(f[1,2], p2, axis = (; title = "sorted order"))
  f

How can i change the order in which the data points are connected?
Thanks!

EDIT: Sorry, somehow i am unable to upload the plot generated by the code above.

1 post - 1 participant