First light
In which I take Makie.jl for a spin to visualize the Palmer Penguins. First challenge: how to color the species.
One of my greatest interests in Julia – at least for now – is how to visualize data. As recommended by the book, I’m following, I’ll use Makie.jl. As discussed in my previous post, please excuse the missing text-output.
begin
using CairoMakie
CairoMakie.activate!()
fig = scatterlines(1:10, 1:10)
endThis produces the following simple chart: 
The next logical step, coming from the ggplot2-verse was to do something with the Palmer Penguins dataset. This is also available in Julia via the PalmerPenguins.jl package.
# load required packages
begin
using DataFrames
using PalmerPenguins
end# setup a function to load the data
function load_penguins()
# in Pluto.jl I had to set my linux's environment variable
# DATADEPS_ALWAYS_ACCEPT=true before running the next line:
table = PalmerPenguins.load()
DataFrame(table)
end# load the data into a DataFrame and drop missing data
# (let's keep this simple)
begin
penguins_raw = load_penguins()
penguins = dropmissing!(penguins_raw)
endNow create a plotting function1:
function penguin_plot_simple()
fig = Figure(;
size=(600,400),
)
ax = Axis(fig[1,1];
xlabel="Body mass",
ylabel="Flipper length",
title="Palmer Penguins",
)
plotobj = scatter!(penguins[!, :body_mass_g], penguins[!, :bill_length_mm])
fig
endThat’s good start. As last step of this miniblog, I struggled with mapping color to the species column. In ggplot2 I would simply map it with aes(color = species), but this failed in Makie.jl. Instead I need to convert the species to a numerical category type, which Makie.jl can use to map color:
begin
# we need this new package:
using CategoricalArrays
# make sure the species column is of type "category"
penguins.species = categorical(penguins.species)
# get integer codes for spcies (note the broadcasting operator '.' after levelcode):
penguins.species_code = levelcode.(penguins.species)
# look at the result in the two relevant columns:
penguins[!, [:species, :species_code]]
endFinally, we can map color to the :species_code column:
function penguin_plot()
fig = Figure(;
size=(600,400),
)
ax = Axis(fig[1,1];
xlabel="Body mass",
ylabel="Flipper length",
title="Palmer Penguins",
)
scatter!(penguins[!, :body_mass_g], penguins[!, :bill_length_mm];
color = penguins[!, :species_code],
colormap=:Dark2_3
)
fig
endGreat! There’s still much to do (legend, theme, maybe some annotations and formatting…) which I will leave open for later posts.
Footnotes
The Julia Data Science book uses functions extensively, even for single plots. In R I have mostly seen this in cases where parametrised plots were generated, but I like the concept, so I’ll follow this recommendation for Julia.↩︎
Reuse
Citation
@misc{gebhard2025,
author = {Gebhard, Christian},
title = {First Light},
date = {2025-06-26},
url = {https://christiangebhard.com/posts/2025-06-26-julia-CO-02/},
langid = {en}
}

