Displays the distribution of LOS (y-axis, log10 scale) across patient age
groups (x-axis) using boxplots. Supports "faceted" (one panel per
centre), "overall" (all centres pooled), and "single"
(one centre) modes.
Usage
plot_los_by_agebin(
data,
mode = c("faceted", "overall", "single"),
center = NULL,
patient_col = "PatientInformation_id",
agebin_col = "Age_bin",
age_col = "age_years",
age_breaks = NULL,
age_labels = NULL,
center_col = "center_name",
admission_col = "admission_date",
discharge_col = "final_outcome_date",
min_los = 1,
max_los = 365,
age_levels = NULL,
fill_colour = "#2C7FB8",
fill_alpha = 0.7,
outlier_alpha = 0.25,
box_width = 0.6,
ncol = 3,
base_size = 14,
title = NULL,
subtitle = NULL,
syndrome_col = NULL,
syndrome_name = NULL
)Arguments
- data
A data frame.
- mode
Character. One of
"faceted","overall", or"single".- center
Character. Centre name required when
mode = "single".- patient_col
Character. Column of patient identifiers.
- agebin_col
Character. Pre-existing age group column. Used when
age_breaksisNULL. Default"Age_bin".- age_col
Character. Continuous age column used when
age_breaksis provided. Default"age_years".- age_breaks
Numeric vector or
NULL. Breakpoints for deriving custom bins fromage_col(e.g.c(0, 5, 15, 30, 50, 70, Inf)).NULL= useagebin_coldirectly.- age_labels
Character vector or
NULL. Labels for each bin created byage_breaks. Must have lengthlength(age_breaks) - 1.NULL= auto-generate from breaks.- center_col
Character. Column of centre identifiers.
- admission_col
Character. Admission date column. Default
"admission_date".- discharge_col
Character. Discharge / final outcome date column. Default
"final_outcome_date".- min_los
Numeric. Minimum LOS (days) to include. Default
1.- max_los
Numeric. Maximum LOS (days) to include. Default
365.- age_levels
Character vector or
NULL. Custom bin order when usingagebin_col.NULL= auto-sort.- fill_colour
Character. Box fill colour. Default
"#2C7FB8".- fill_alpha
Numeric. Box fill transparency (0-1). Default
0.7.- outlier_alpha
Numeric. Outlier point transparency (0-1). Default
0.25.- box_width
Numeric. Width of each box. Default
0.6.- ncol
Integer. Number of facet columns (
mode = "faceted"only). Default3.- base_size
Numeric. Base font size. Default
14.- title
Character or
NULL. Plot title. Auto-generated ifNULL.- subtitle
Character or
NULL. Plot subtitle.NULL= none.- syndrome_col
Character or
NULL. Syndrome column for pre-filtering. DefaultNULL.- syndrome_name
Character or
NULL. Syndrome value to retain. Requiressyndrome_col. DefaultNULL.
Details
LOS is computed as difftime(discharge_col, admission_col, units = "days").
One row per unique patient x centre x admission x discharge is retained.
Rows with LOS < min_los or LOS > max_los are dropped.
Two ways to supply age groups:
Pre-existing column (default) – set
agebin_colto an existing categorical column (e.g."Age_bin"). Bins are sorted automatically (<1,1-5, ...,85+); override order withage_levels.Custom breaks from continuous age – set
age_breaksto a numeric vector (e.g.c(0, 5, 15, 30, 50, 70, Inf)) andage_colto the continuous age column (default"age_years"). Bins are derived viacut()and labelled automatically.agebin_colis ignored whenage_breaksis provided.