Draws a full-arch odontogram with colour-coded tooth surfaces. Supports primary and permanent dentition (5–8 teeth per quadrant), selective surfaces, stratification, summary statistics with significance testing, and configurable tooth numbering.
build_odontogram(
data,
value_col = "prop",
dentition = "permanent",
teeth_per_quadrant = NULL,
title = "Surface Odontogram",
subtitle = NULL,
color_low = "#FFFFFF",
color_high = "#C62828",
na_color = "grey90",
min_val = NULL,
max_val = NULL,
legend_title = "Proportion",
show_roots = TRUE,
surfaces = c("buc", "lin", "mes", "dis", "occ", "rootb", "rootl", "rootm", "rootd"),
show_labels = TRUE,
label_size = 1.8,
tooth_label_size = 3,
numbering = c("quadrant", "fdi", "universal"),
strata = NULL,
strata_labels = NULL,
stats = NULL,
stats_test = NULL,
stats_var = NULL,
stats_raw = NULL,
footnote = NULL,
combine = TRUE,
ncol = 1
)A ggplot object (or list of ggplots if combine = FALSE).
Data frame with at least tooth_num (e.g. "ur1"),
tooth_surface (e.g. "buc", "occ", "rootb"), and a numeric value
column. If stratifying, include the column named in strata.
Name of the numeric column to map to fill colour.
"permanent" or "primary".
Integer 5–8 (default derived from dentition).
Plot title/subtitle.
Gradient endpoints (default "#FFFFFF" to
"#C62828").
Fill for missing surfaces (default "grey90").
Lower and upper limits for the colour scale. Both auto-detected when NULL. Set manually to fix the range across multiple plots.
Legend title.
Logical; draw root caries bars.
Character vector of surfaces to draw.
Logical; show surface abbreviation labels (B, L, M, D, O, RB, RL, RM, RD) inside each surface polygon.
Numeric; size of surface labels.
Numeric; size of tooth number labels (default 3).
Tooth numbering system for display: "quadrant" (default),
"fdi", or "universal".
Optional column name for stratification.
Optional named character vector to relabel strata in panel titles.
Optional data frame of per-group summary statistics to display
below each panel. Must contain a column matching strata and numeric
columns to display (e.g. n, mean_DMFT, mean_DT). See Details.
Method for comparing stats across strata: "t" for
t-test (default), "wilcox" for Wilcoxon rank-sum, or NULL to skip.
P-values are shown as significance stars.
Column name in stats_raw to test for differences (e.g.
"DMFT"). Required when stats_test is not NULL.
Optional data frame of individual-level data used for
significance testing. Must contain a column matching strata and a
numeric column matching stats_var. Required when stats_test is set.
Optional character string displayed below the plot as a caption. Use for abbreviation explanations and p-value definitions.
Logical; if strata is set, combine panels into one plot
(default TRUE) or return a named list.
Number of columns when combining stratified panels.
Summary statistics: Pass a data frame to stats with one row per
stratum. Example:
stats_df <- data.frame(
treatment = c("SDF", "ART"),
n = c(120, 115),
mean_DT = c(2.3, 2.8),
mean_DMFT = c(5.1, 5.6)
)
build_odontogram(d, strata = "treatment", stats = stats_df)
Significance stars: When stats_test and stats_var are set and
raw data is provided via stats_raw, p-values are computed and appended:
*** p < 0.001, ** p < 0.01, * p < 0.05, ns otherwise.
library(tibble)
d <- expand.grid(
tooth_num = paste0(rep(c("ur","ul","lr","ll"), each=7), 1:7),
tooth_surface = c("buc","lin","mes","dis","occ"),
stringsAsFactors = FALSE
)
d$prop <- runif(nrow(d))
build_odontogram(d, teeth_per_quadrant = 7)
Run the code above in your browser using DataLab