Table Structure
These functions control high-level layout: column spanners, the stub (row-label) column, and row groups.
spanner!
Add a spanning header above a group of columns.
Signatures:
spanner!(tbl, (colgroup => label)::Pair...)
spanner!(tbl, d::AbstractDict)
spanner!(tbl, d::AbstractVector{<:Pair})using StyledTables, SummaryTables, DataFrames
df = DataFrame(
drug = ["Aspirin", "Ibuprofen", "Naproxen"],
dose_mg = [100, 200, 250],
efficacy = [0.72, 0.81, 0.78],
safety = [0.91, 0.84, 0.88],
)
tbl = StyledTable(df)
spanner!(tbl, [:efficacy, :safety] => "Outcomes")
relabel!(tbl,
:drug => "Drug",
:dose_mg => "Dose (mg)",
:efficacy => "Efficacy",
:safety => "Safety",
)
format!(PercentFormatter(digits = 1), tbl, [:efficacy, :safety])
render(tbl)| Outcomes | |||
| Drug | Dose (mg) | Efficacy | Safety |
| Aspirin | 100 | 72.0% | 91.0% |
| Ibuprofen | 200 | 81.0% | 84.0% |
| Naproxen | 250 | 78.0% | 88.0% |
Multiple spanners can be added at once:
tbl = StyledTable(df)
spanner!(tbl, [:dose_mg] => "Dosing", [:efficacy, :safety] => "Outcomes")
render(tbl)| Dosing | Outcomes | ||
| drug | dose_mg | efficacy | safety |
| Aspirin | 100 | 0.72 | 0.91 |
| Ibuprofen | 200 | 0.81 | 0.84 |
| Naproxen | 250 | 0.78 | 0.88 |
Multi-line spanner header using Multiline:
tbl = StyledTable(df)
spanner!(tbl, [:efficacy, :safety] => Multiline("Outcomes", "(primary)"))
render(tbl)| Outcomes (primary) |
|||
| drug | dose_mg | efficacy | safety |
| Aspirin | 100 | 0.72 | 0.91 |
| Ibuprofen | 200 | 0.81 | 0.84 |
| Naproxen | 250 | 0.78 | 0.88 |
StyledTables.spanner! Method
spanner!(
tbl::StyledTable,
args::Pair...;
level
) -> StyledTableAdd one or more spanning header labels above groups of columns.
Each spanner is given as a columns => label pair, where columns is a Vector{Symbol} of column names to span and label is the spanner text (a String, SummaryTables.Multiline, or any value accepted by SummaryTables.Cell).
Use the level keyword to stack spanners in multiple rows: level = 1 (the default) is the bottom-most row, closest to the column labels; level = 2 sits above it, and so on. A higher-level spanner's column set must fully contain every lower-level spanner it overlaps.
Arguments
tbl: theStyledTableto modify.args: one or morecolumn(s) => labelpairs.level: the spanner row (default1).
Returns
tbl (modified in place).
Examples
tbl = StyledTable(df)
spanner!(tbl, [:efficacy, :safety] => "Outcomes")
render(tbl)
tbl = StyledTable(df)
spanner!(tbl, [:bill_len, :bill_depth, :flipper_len] => "Length (mm)")
spanner!(tbl, [:bill_len, :bill_depth, :flipper_len, :body_mass] => "Physical measurements"; level = 2)
render(tbl)
using SummaryTables: Multiline
tbl = StyledTable(df)
spanner!(tbl, [:dose, :response] => Multiline("Treatment", "(N=50)"))
render(tbl)StyledTables.spanner! Method
spanner!(
tbl::StyledTable,
d::Union{AbstractDict{Vector{Symbol}, Symbol}, AbstractDict{Symbol, Symbol}, AbstractDict{Symbol, Multiline}, AbstractDict{<:AbstractVector{<:AbstractString}, <:AbstractString}, AbstractDict{<:AbstractVector{<:AbstractString}, Symbol}, AbstractDict{Vector{Symbol}, <:AbstractString}, AbstractDict{<:AbstractString, <:AbstractString}, AbstractDict{<:AbstractString, Symbol}, AbstractDict{Symbol, <:AbstractString}, AbstractDict{<:AbstractString, Multiline}, AbstractVector{<:Pair{<:AbstractVector{<:AbstractString}, <:AbstractString}}, AbstractVector{<:Pair{Vector{Symbol}, Symbol}}, AbstractVector{<:Pair{<:AbstractVector{<:AbstractString}, Symbol}}, AbstractVector{<:Pair{Vector{Symbol}, <:AbstractString}}, AbstractVector{<:Pair{<:AbstractString, <:AbstractString}}, AbstractVector{<:Pair{<:AbstractString, Symbol}}, AbstractVector{<:Pair{Symbol, <:AbstractString}}, AbstractVector{<:Pair{Symbol, Symbol}}, AbstractVector{<:Pair{Symbol, Multiline}}, AbstractVector{<:Pair{<:AbstractString, Multiline}}};
level
) -> StyledTableAdd spanning headers from a dict or vector of pairs.
Arguments
tbl: theStyledTableto modify.d: anAbstractDictorAbstractVectorpairing column names to spanner labels.level: the spanner row applied to every entry ind(default1).
Returns
tbl (modified in place).
See also: spanner!, header!, stub!.
Examples
tbl = StyledTable(df)
spanner!(tbl, Dict(
[:efficacy, :safety] => "Outcomes",
[:age, :sex] => "Demographics")
)
render(tbl)stub!
Mark one column as the stub: a row-label column rendered apart from data columns. By default the stub header is not bolded; it gains a bold label if stubhead! is called.
Signature: stub!(tbl, col::Symbol)
tbl = StyledTable(df)
stub!(tbl, :drug)
relabel!(tbl, :dose_mg => "Dose (mg)", :efficacy => "Efficacy", :safety => "Safety")
render(tbl)| Dose (mg) | Efficacy | Safety | |
| Aspirin | 100 | 0.72 | 0.91 |
| Ibuprofen | 200 | 0.81 | 0.84 |
| Naproxen | 250 | 0.78 | 0.88 |
StyledTables.stub! Function
stub!(tbl::StyledTable, col::Symbol) -> StyledTableMark a column as the stub (row-label column).
The stub header is not bolded. Use stubhead! to label it.
Arguments
tbl: theStyledTableto modify.col: name of the column to use as the stub.
Returns
tbl (modified in place).
See also: stubhead!, rowgroup!.
Examples
tbl = StyledTable(df)
stub!(tbl, :drug)
render(tbl)stubhead!
Label the stub column header. Has no effect without a prior call to stub!.
Signature: stubhead!(tbl, label)
tbl = StyledTable(df)
stub!(tbl, :drug)
stubhead!(tbl, "Drug Name")
render(tbl)| Drug Name | dose_mg | efficacy | safety |
| Aspirin | 100 | 0.72 | 0.91 |
| Ibuprofen | 200 | 0.81 | 0.84 |
| Naproxen | 250 | 0.78 | 0.88 |
StyledTables.stubhead! Function
stubhead!(tbl::StyledTable, label) -> StyledTableSet the stub column header label.
Requires a prior call to stub!.
Arguments
tbl: theStyledTableto modify.label: display text for the stub header cell.
Returns
tbl (modified in place).
See also: stub!.
Examples
tbl = StyledTable(df)
stub!(tbl, :drug)
stubhead!(tbl, "Drug Name")
render(tbl)rowgroup!
Group rows by distinct values in a column. A bold group-label row precedes each new group. Data rows are indented.
Signature: rowgroup!(tbl, col::Symbol; indent_pt = 12)
df = DataFrame(
category = ["Analgesic", "Analgesic", "NSAID", "NSAID"],
drug = ["Aspirin", "Paracetamol", "Ibuprofen", "Naproxen"],
dose_mg = [100, 500, 200, 250],
)
tbl = StyledTable(df)
rowgroup!(tbl, :category)
hide!(tbl, :category)
relabel!(tbl, :drug => "Drug", :dose_mg => "Dose (mg)")
render(tbl)| Drug | Dose (mg) |
| Analgesic | |
| Aspirin | 100 |
| Paracetamol | 500 |
| NSAID | |
| Ibuprofen | 200 |
| Naproxen | 250 |
To increase indentation:
tbl = StyledTable(df)
rowgroup!(tbl, :category; indent_pt = 20)
hide!(tbl, :category)
render(tbl)| drug | dose_mg |
| Analgesic | |
| Aspirin | 100 |
| Paracetamol | 500 |
| NSAID | |
| Ibuprofen | 200 |
| Naproxen | 250 |
StyledTables.rowgroup! Function
rowgroup!(
tbl::StyledTable,
col::Symbol;
indent_pt,
full_width
) -> StyledTableGroup rows by distinct values in a column.
A bold group-label row precedes each new group value. Data rows are indented by indent_pt points. Hide the grouping column afterwards with hide!.
Arguments
tbl: theStyledTableto modify.col: column whose distinct values define the groups.
Keywords
indent_pt: left indent for data rows within a group (default12).full_width: whether group-label rows span the entire table width (defaultfalse).
Returns
tbl (modified in place).
Examples
tbl = StyledTable(df)
rowgroup!(tbl, :category)
hide!(tbl, :category)
render(tbl)