How to order axis with categorical variable in AlgebraOfGraphics?

By default a categorical variable is sorted according to its own values, but you can specify an alternative order with mapping(:c => sorter(...)) :

using CairoMakie, AlgebraOfGraphics, DataFrames

df = DataFrame(x = [0.15, 0.13, 0.17], c = ["A", "B", "C"])

c_order = sort(df, :x).c

plt = data(df) *
      mapping(:x, :c => sorter(c_order), color=:c) *
      visual(markersize=40)

draw(plt; axis=(; limits=((0.1, 0.2), nothing), xticks=0.1:0.02:0.2))

1 Like