Penguins, no AoG

using CairoMakie, PalmerPenguins, DataFrames
using GLM: lm, @formula, predict

function getPenguins()
    ENV["DATADEPS_ALWAYS_ACCEPT"] = "true"
    penguins = dropmissing(DataFrame(PalmerPenguins.load()))
    return penguins
end

function plotPenguins()
    penguins = getPenguins()
    palette = (color=tuple.(["#FC7808", "#8C00EC", "#107A78"], 0.65),
        marker=[:circle, :utriangle, :rect])
    cycle = Cycle([:color, :marker], covary=true)
    with_theme(theme_light(), palette=palette, Scatter=(cycle=cycle,)) do
        fig = Figure(resolution=(600, 400))
        ax = Axis(fig[1, 1], title="Flipper and bill length",
            xlabel="Flipper length (mm)", ylabel="Bill length (mm)")
        for penguin in ["Adelie", "Chinstrap", "Gentoo"]
            specie = filter(:species => ==(penguin), penguins)
            x = specie[!, :flipper_length_mm]
            y = specie[!, :bill_length_mm]
            linearModel = lm(@formula(Y ~ X), DataFrame(X=x, Y=y))
            ŷ = predict(linearModel)
            scatter!(ax, x, y; markersize=12, label=penguin)
            lines!(ax, x, ŷ; label=penguin, linewidth=4)
        end
        axislegend("Penguin species", position=:rb, bgcolor=(:grey90, 0.15),
            titlesize=12, labelsize=12, merge=true)
        return fig
    end
end
fig = plotPenguins()

Warning

This example was autogenerated using:

using Pkg
Pkg.status(["CairoMakie", "PalmerPenguins", "DataFrames", "GLM"])
Status `~/work/BeautifulMakie/BeautifulMakie/docs/Project.toml`
  [13f3f980] CairoMakie v0.10.6
  [a93c6f00] DataFrames v1.5.0
  [38e38edf] GLM v1.8.3
  [8b842266] PalmerPenguins v0.1.4

This page was generated using Literate.jl.