Create publication-quality figures and tables for academic manuscripts in R using ggplot2 and kableExtra. Apply when creating or refining visualisations of epidemiological data, model results, or summary statistics. Covers journal formatting, captions, and accessibility.
theme_classic() or theme_bw() with minimal gridlinespatchwork with plot_annotation(tag_levels = "A")scale_*_brewer() with qualitative palettes for categorical dataviridis or RColorBrewer "Set2", "Dark2"scale_x_date(date_labels = "%b %Y") for time axesCoefficient/forest plots:
Time series:
Score distributions:
library(kableExtra)
df |>
kbl(
caption = "Table 1. Descriptive characteristics of included models.",
digits = 2,
col.names = c("Characteristic", "N", "Median (IQR)")
) |>
kable_styling(full_width = FALSE) |>
pack_rows("Model type", 1, 3) |>
pack_rows("Geographic scope", 4, 5) |>
footnote(general = "IQR = interquartile range.")
pack_rows()Captions must be standalone. A reader should understand the figure or table without reading the main text.
Structure:
Example:
Figure 2. Adjusted partial effects of model method on forecast accuracy. Panel A shows effects on case forecasts; Panel B shows effects on death forecasts. Points indicate posterior mean partial effects from the GAMM; whiskers show 95% confidence intervals. The dashed line indicates no difference from the overall mean. WIS = weighted interval score; GAMM = generalised additive mixed model.
ggsave(
here("output", "plots", "figure-1.tif"),
plot = fig1,
width = 170, height = 120, units = "mm",
dpi = 300
)