Code
using Arrow using AlgebraOfGraphics -using CairoMakie # for displaying static plots +using CairoMakie # for displaying static plots using DataFrames using Statistics using StatsBase @@ -407,7 +423,7 @@
Creating multi-panel plots
activate!(; type="svg") # use SVG (other options include PNG) CairoMakie.
= dataset("fggk21") tbl
Arrow.Table with 525126 rows, 7 columns, and schema:
@@ -420,13 +436,13 @@ Creating multi-panel plots
:score Float64
typeof(tbl)
Arrow.Table
= DataFrame(tbl) df typeof(df)
1 Creating a summ
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-score = [ # establish order and labels of tbl.Test @@ -451,7 +467,7 @@ tlabels
1 Creating a summ ];
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.
= combine( df2 groupby( select(df, :, :age => ByRow(x -> round(x; digits=1)) => :age), @@ -462,9 +478,9 @@
1 Creating a summ )
Row | Sex | Test | @@ -699,7 +715,7 @@
---|