This notebook shows creating a multi-panel plot similar to Figure 2 of Fühner et al. (2021).
The data are available from the SMLP2026 example datasets.
Code
usingArrowusingAlgebraOfGraphicsusingCairoMakie# for displaying static plotsusingDataFramesusingStatisticsusingStatsBaseusingSMLP2026: dataset
Precompiling packages...
Info Given Arrow was explicitly requested, output will be shown live
WARNING: Constructor for type "Type" was extended in `Flatbuf` without explicit qualification or import.
NOTE: Assumed "Type" refers to `Base.Type`. This behavior is deprecated and may differ in future versions.`
NOTE: This behavior may have differed in Julia versions prior to 1.12.
Hint: If you intended to create a new generic function of the same name, use `function Type end`.
Hint: To silence the warning, qualify `Type` as `Base.Type` in the method signature or explicitly `import Base: Type`.
4823.8 ms ✓ Arrow
1 dependency successfully precompiled in 5 seconds. 49 already precompiled.
1 dependency had output during precompilation:
┌ Arrow
│ [Output was shown above]
└ Precompiling packages...
945.0 ms ✓ QuartoNotebookWorkerTablesExt (serial)
1 dependency successfully precompiled in 1 seconds
Precompiling packages...
1255.8 ms ✓ Bzip2_jll
1329.9 ms ✓ Rmath_jll
1337.7 ms ✓ Xorg_libXau_jll
1333.7 ms ✓ libpng_jll
1360.8 ms ✓ Libmount_jll
1374.4 ms ✓ LLVMOpenMP_jll
1387.3 ms ✓ libfdk_aac_jll
1599.4 ms ✓ Graphite2_jll
1789.5 ms ✓ Imath_jll
1481.2 ms ✓ Giflib_jll
1461.1 ms ✓ LAME_jll
1462.9 ms ✓ LERC_jll
1539.4 ms ✓ CRlibm_jll
1540.6 ms ✓ XZ_jll
1410.4 ms ✓ Ogg_jll
1686.2 ms ✓ EarCut_jll
1904.8 ms ✓ JpegTurbo_jll
1828.9 ms ✓ Xorg_libXdmcp_jll
1245.7 ms ✓ x265_jll
1233.7 ms ✓ Opus_jll
1456.9 ms ✓ libaom_jll
1239.8 ms ✓ Xorg_xtrans_jll
1423.1 ms ✓ LZO_jll
1627.5 ms ✓ x264_jll
1536.4 ms ✓ Expat_jll
1414.6 ms ✓ Libffi_jll
1339.9 ms ✓ isoband_jll
1526.8 ms ✓ FFTW_jll
1311.8 ms ✓ OpenSpecFun_jll
1379.6 ms ✓ OpenBLASConsistentFPCSR_jll
1487.9 ms ✓ Libuuid_jll
1488.2 ms ✓ FriBidi_jll
1606.9 ms ✓ GettextRuntime_jll
1433.6 ms ✓ FreeType2_jll
2558.7 ms ✓ IntelOpenMP_jll
2805.6 ms ✓ oneTBB_jll
1648.9 ms ✓ Rmath
1601.6 ms ✓ Pixman_jll
1422.3 ms ✓ CRlibm
2017.1 ms ✓ OpenEXR_jll
1624.5 ms ✓ Libtiff_jll
691.5 ms ✓ Isoband
2390.8 ms ✓ libvorbis_jll
1514.8 ms ✓ libsixel_jll
2113.3 ms ✓ FreeType
2812.6 ms ✓ Glib_jll
9750.6 ms ✓ ColorSchemes
5620.2 ms ✓ Xorg_libxcb_jll
2524.3 ms ✓ Fontconfig_jll
2758.7 ms ✓ MKL_jll
11398.7 ms ✓ JSON
7002.8 ms ✓ SpecialFunctions
2266.7 ms ✓ Xorg_libX11_jll
3822.3 ms ✓ OpenEXR
3076.7 ms ✓ ColorBrewer
2481.2 ms ✓ HypergeometricFunctions
1219.3 ms ✓ ColorVectorSpace → SpecialFunctionsExt
5180.0 ms ✓ SpecialFunctions → SpecialFunctionsChainRulesCoreExt
2017.7 ms ✓ Xorg_libXext_jll
2478.6 ms ✓ Xorg_libXrender_jll
10072.4 ms ✓ IntervalArithmetic
21089.5 ms ✓ StaticArrays
1448.8 ms ✓ IntervalArithmetic → IntervalArithmeticSparseArraysExt
1060.9 ms ✓ IntervalArithmetic → IntervalArithmeticIntervalSetsExt
2354.3 ms ✓ Cairo_jll
2710.3 ms ✓ Libglvnd_jll
1233.7 ms ✓ IntervalArithmetic → IntervalArithmeticLinearAlgebraExt
1224.1 ms ✓ StaticArrays → StaticArraysStatisticsExt
1340.6 ms ✓ ConstructionBase → ConstructionBaseStaticArraysExt
1709.2 ms ✓ Adapt → AdaptStaticArraysExt
1857.2 ms ✓ Accessors → StaticArraysExt
7242.7 ms ✓ StatsFuns
5522.7 ms ✓ StaticArrays → StaticArraysChainRulesCoreExt
2297.4 ms ✓ HarfBuzz_jll
895.9 ms ✓ StatsFuns → StatsFunsInverseFunctionsExt
29814.0 ms ✓ SIMD
3736.0 ms ✓ libwebp_jll
6757.7 ms ✓ StructArrays → StructArraysStaticArraysExt
2235.8 ms ✓ Loess
3330.4 ms ✓ StatsFuns → StatsFunsChainRulesCoreExt
2889.1 ms ✓ libass_jll
5841.6 ms ✓ StatsModels
28240.7 ms ✓ FFTW
13764.1 ms ✓ ExactPredicates
11483.0 ms ✓ Interpolations
3996.5 ms ✓ FFMPEG_jll
3952.5 ms ✓ Interpolations → InterpolationsUnitfulExt
35061.0 ms ✓ PlotUtils
16612.7 ms ✓ Distributions
4184.2 ms ✓ Distributions → DistributionsTestExt
5146.6 ms ✓ GLM
6760.2 ms ✓ Distributions → DistributionsChainRulesCoreExt
13077.9 ms ✓ DelaunayTriangulation
55359.5 ms ✓ ImageCore
3409.6 ms ✓ KernelDensity
6558.6 ms ✓ ImageBase
6953.5 ms ✓ WebP
8762.2 ms ✓ JpegTurbo
39842.6 ms ✓ GeometryBasics
10166.7 ms ✓ Sixel
5146.4 ms ✓ ImageAxes
2779.2 ms ✓ Packing
3732.6 ms ✓ GeometryBasics → GeometryBasicsGeoInterfaceExt
12983.4 ms ✓ PNGFiles
5072.0 ms ✓ ShaderAbstractions
2443.0 ms ✓ ImageMetadata
34396.3 ms ✓ Automa
4416.1 ms ✓ FreeTypeAbstraction
2649.9 ms ✓ Netpbm
9375.2 ms ✓ MakieCore
11708.5 ms ✓ GridLayoutBase
7704.5 ms ✓ MathTeXEngine
52627.1 ms ✓ TiffImages
116565.3 ms ✓ Makie
40641.2 ms ✓ AlgebraOfGraphics
4586.6 ms ✓ AlgebraOfGraphics → AlgebraOfGraphicsUnitfulExt
116 dependencies successfully precompiled in 256 seconds. 179 already precompiled.
Precompiling packages...
1673.8 ms ✓ QuartoNotebookWorkerLaTeXStringsExt (serial)
1 dependency successfully precompiled in 2 seconds
Precompiling packages...
363.5 ms ✓ InlineStrings → ParsersExt
1 dependency successfully precompiled in 0 seconds. 9 already precompiled.
Precompiling packages...
1039.0 ms ✓ QuartoNotebookWorkerJSONExt (serial)
1 dependency successfully precompiled in 1 seconds
Precompiling packages...
424.8 ms ✓ JSON → JSONArrowExt
1 dependency successfully precompiled in 0 seconds. 12 already precompiled.
Precompiling packages...
5227.8 ms ✓ QuartoNotebookWorkerMakieExt (serial)
1 dependency successfully precompiled in 5 seconds
Precompiling packages...
761.6 ms ✓ Pango_jll
1956.8 ms ✓ Cairo
37689.5 ms ✓ CairoMakie
3 dependencies successfully precompiled in 41 seconds. 272 already precompiled.
Precompiling packages...
4861.4 ms ✓ QuartoNotebookWorkerCairoMakieExt (serial)
1 dependency successfully precompiled in 5 seconds
Precompiling packages...
1493.4 ms ✓ StringManipulation
20561.2 ms ✓ PrettyTables
39541.3 ms ✓ DataFrames
3 dependencies successfully precompiled in 62 seconds. 33 already precompiled.
Precompiling packages...
1156.9 ms ✓ CategoricalArrays → CategoricalArraysJSONExt
1199.2 ms ✓ JSON3 → JSON3ArrowExt
1445.9 ms ✓ NLopt_jll
1561.2 ms ✓ ChunkCodecLibZstd
2008.9 ms ✓ WeakRefStrings
910.6 ms ✓ IntervalArithmetic → IntervalArithmeticDiffRulesExt
3032.9 ms ✓ FastGaussQuadrature
1932.7 ms ✓ Conda
2720.2 ms ✓ CategoricalArrays → CategoricalArraysArrowExt
3182.2 ms ✓ MixedModelsDatasets
2236.2 ms ✓ RegressionFormulae
2573.9 ms ✓ StandardizedPredictors
1949.4 ms ✓ NLopt
6462.0 ms ✓ DataFrameMacros
8642.2 ms ✓ Static
9050.2 ms ✓ ForwardDiff
1583.8 ms ✓ Unitful → ForwardDiffExt
1671.6 ms ✓ ForwardDiff → ForwardDiffStaticArraysExt
7436.9 ms ✓ BoxCox
1969.1 ms ✓ BoxCox → BoxCoxStatsModelsExt
4239.0 ms ✓ IntervalArithmetic → IntervalArithmeticForwardDiffExt
4758.5 ms ✓ Effects
19034.0 ms ✓ RCall → RCallAxisArraysExt
2531.7 ms ✓ Effects → EffectsGLMExt
23401.0 ms ✓ ArrayLayouts
2445.5 ms ✓ ArrayLayouts → ArrayLayoutsSparseArraysExt
26248.3 ms ✓ CSV
28251.4 ms ✓ BoxCox → BoxCoxMakieExt
25484.1 ms ✓ BandedMatrices
45406.2 ms ✓ JLD2
1688.1 ms ✓ BandedMatrices → BandedMatricesSparseArraysExt
10559.2 ms ✓ BSplineKit
52217.6 ms ✓ MixedModels
4623.6 ms ✓ BoxCox → BoxCoxMixedModelsExt
4843.8 ms ✓ MixedModels → MixedModelsForwardDiffExt
5824.5 ms ✓ Effects → EffectsMixedModelsExt
5504.8 ms ✓ MixedModelsExtras
5621.4 ms ✓ MixedModelsSim
5912.6 ms ✓ MixedModelsSerialization
5007.4 ms ✓ MixedModelsSerialization → MixedModelsSerializationEffectsExt
41601.8 ms ✓ MixedModelsMakie
7193.3 ms ✓ SMLP2026
42 dependencies successfully precompiled in 167 seconds. 349 already precompiled.
Precompiling packages...
1045.1 ms ✓ QuartoNotebookWorkerJSON3Ext (serial)
1 dependency successfully precompiled in 1 seconds
The response to be plotted is the mean score by Test and Sex and age, rounded to the nearest 0.1 years.
The first task is to round the age to 1 digit after the decimal place, which can be done with select applied to a DataFrame. In some ways this is the most complicated expression in creating the plot so we will break it down. select is applied to DataFrame(dat), which is the conversion of the Arrow.Table, dat, to a DataFrame. This is necessary because an Arrow.Table is immutable but a DataFrame can be modified.
The arguments after the DataFrame describe how to modify the contents. The first : indicates that all the existing columns should be included. The other expression can be pairs (created with the => operator) of the form :col => function or of the form :col => function => :newname. (See the documentation of the DataFrames package for details.)
In this case the function is an anonymous function of the form round.(x, digits=1) where “dot-broadcasting” is used to apply to the entire column (see this documentation for details).
transform!(df, :age, :age => (x -> x .-8.5) =>:a1) # centered age (linear)select!(groupby(df, :Test), :, :score => zscore =>:zScore) # z-scoretlabels = [ # establish order and labels of tbl.Test"Run"=>"Endurance","Star_r"=>"Coordination","S20_r"=>"Speed","SLJ"=>"PowerLOW","BPT"=>"PowerUP",];
The next stage is a group-apply-combine operation to group the rows by Sex, Test and rnd_age then apply mean to the zScore and also apply length to zScore to record the number in each group.
The AlgebraOfGraphics package applies operators to the results of functions such as data (specify the data table to be used), mapping (designate the roles of columns), and visual (type of visual presentation).
let design =mapping(:age, :zScore; color=:Sex, col=:Test) lines = design *linear() means = design *visual(Scatter; markersize=5)draw(data(df2) * means +data(df) * lines)end
TBD: Relabel factor levels (Boys, Girls; fitness components for Test)
TBD: Relevel factors; why not levels from Tables?
TBD: Set range (7.8 to 9.2 and tick marks (8, 8.5, 9) of axes.
TBD: Move legend in plot?
Fühner, T., Granacher, U., Golle, K., & Kliegl, R. (2021). Age and sex effects in physical fitness components of 108,295 third graders including 515 primary schools and 9 cohorts. Scientific Reports, 11(1). https://doi.org/10.1038/s41598-021-97000-4
This page was rendered from git revision f875caa
using Quarto 1.8.26.