How to make a quaternary plot

Something like this?

using GLMakie
using Makie.Distributions 
x = rand(Dirichlet([5,1,1,5]), 100)

s = Scene(camera = cam3d!)

p1 = Point3f(sqrt(8/9), 0, -1/3)
p2 = Point3f(-sqrt(2/9), sqrt(2/3), -1/3)
p3 = Point3f(-sqrt(2/9), -sqrt(2/3), -1/3)
p4 = Point3f(0, 0, 1.0)

frame = linesegments!(
    s,
    [
        (p1, p2),
        (p1, p3),
        (p1, p4),
        (p2, p3),
        (p2, p4),
        (p3, p4),
    ],
    color = :black,
)

text!(s, [p1, p2, p3, p4] .* 1.2, text = ["P1", "P2", "P3", "P4"], align = (:center, :center))

function to_quaternary(v1, v2, v3, v4, p1, p2, p3, p4)
    v1 * p1 + v2 * p2 + v3 * p3 + v4 * p4
end

scatter!(s, [to_quaternary(c[1], c[2], c[3], c[4], p1, p2, p3, p4) for c in eachcol(x)])

zoom!(s, 0.7)
s

1 Like