| Title: | Forest Plots with a Heatmap of Study Properties |
|---|---|
| Description: | Draws a forest plot of the studies in a meta-analysis, sorted by effect size, above a heatmap of study properties such as population, design or country. Supply one row per study (effect size and 95% confidence interval) and the factor columns describing each study; the plot shows at a glance whether studies with particular properties tend to find larger or smaller effects. |
| Authors: | Shaheed Azaad [aut, cre], The Roboto Project Authors [cph] (Roboto Condensed font in inst/fonts (SIL Open Font License 1.1)) |
| Maintainer: | Shaheed Azaad <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-11-05 00:56:45 UTC |
| Source: | https://github.com/shaheedazaad/forestmap |
Made-up studies from a meta-analysis of an intervention: each study's
standardised mean difference and sampling variance (the yi/vi pair
that metafor::escalc() produces), its sample size, and four study
properties. Some studies don't report their outcome
measure or country (NA). Use it to try out plot_forestmap().
forestmap_exampleforestmap_example
A data frame with 60 rows (studies) and 8 columns:
Study label (first author and year).
Standardised mean difference (Hedges' g).
Sampling variance of smd.
Total sample size.
Factor: Adults, Children or Clinical.
Factor: Self-report or Behavioural; NA = not
reported.
Factor: RCT or Quasi-experimental.
Factor: USA, UK, Australia, Germany or Canada;
NA = not reported.
Simulated; see data-raw/forestmap_example.R in the package source.
Ready-made palettes that can be passed by name to the palette argument of
plot_forestmap(). Each palette has three colours:
forestmap_palettesforestmap_palettes
A named list of named character vectors (hex colours):
Blue / red / grey.
Blue and vermillion from the Okabe-Ito palette (Okabe & Ito, 2008), designed to stay distinguishable with common colour-vision deficiencies; light grey for null.
Teal / purple / grey.
Black / dark grey / light grey, for print.
positive: the 95% CI lies entirely above the null value.
negative: the 95% CI lies entirely below the null value.
null: the 95% CI includes the null value.
names(forestmap_palettes) forestmap_palettes$okabe_itonames(forestmap_palettes) forestmap_palettes$okabe_ito
Plots each study's effect size and 95% confidence interval, sorted from smallest to largest, above a heatmap showing each study's properties (population, design, country, ...). It shows at a glance whether studies with particular properties tend to find larger or smaller effects.
plot_forestmap( data, es, lb = NULL, ub = NULL, moderators, vi = NULL, se = NULL, font = "Roboto Condensed", palette = "default", text_size = 9, forest_height = "auto", null_value = 0, rope = NULL, y_limits = NULL, y_label = "Effect size", x_label = "Effect", max_levels = NULL, layout = c("standard", "compact") )plot_forestmap( data, es, lb = NULL, ub = NULL, moderators, vi = NULL, se = NULL, font = "Roboto Condensed", palette = "default", text_size = 9, forest_height = "auto", null_value = 0, rope = NULL, y_limits = NULL, y_label = "Effect size", x_label = "Effect", max_levels = NULL, layout = c("standard", "compact") )
data |
A data frame with one row per study. |
es |
Name of the column holding each study's effect size. |
lb, ub
|
Names of the columns holding the lower and upper bounds of
each study's 95% confidence interval. Give these, or |
moderators |
Names of the columns holding study properties (factors).
Name the vector to set each moderator's heading, e.g.
|
vi |
Name of a column holding each study's sampling variance (e.g.
|
se |
Name of a column holding each study's standard error. The 95%
confidence interval is computed as |
font |
A font family installed on your computer (e.g. |
palette |
A palette name from forestmap_palettes ( |
text_size |
Base text size in points. |
forest_height |
Share of the plot's height given to the forest plot
(the top panel), between 0 and 1 ( |
null_value |
The value meaning "no effect": |
rope |
Optional region of practical equivalence, drawn as a shaded
band: two numbers such as |
y_limits |
Optional y-axis limits, e.g. |
y_label, x_label
|
Axis titles. |
max_levels |
Optional maximum number of rows per moderator. With
|
layout |
|
Each row of data is one study. Effects are coloured by their confidence
interval: positive when it lies entirely above null_value, negative
when entirely below, and null otherwise. Each study's heatmap tiles take
the same colour.
A patchwork object. Print it to
display it, or save it with ggplot2::ggsave().
Each moderator (study property) gets its own block in the heatmap with one
row per factor level, in the order of the factor's levels. Use factor()
with levels = to control the order. A missing value (NA) means the
study doesn't report that property, so it gets no filled tile in that
block. Character columns are converted to factors (with a message).
The plot has no fixed physical size; choose the width and height when you
save it, e.g. ggplot2::ggsave("plot.png", p, width = 7, height = 5.25).
forest_height and text_size control proportions and text.
PNG and SVG files saved with ggplot2::ggsave() always use the chosen
font. Some other graphics devices only see fonts installed on your
computer, and show the bundled Roboto Condensed in another font until you
install it (the files are in system.file("fonts", package = "forestmap")):
RStudio's Plots pane: or set Tools > Global Options > General > Graphics > Backend to AGG.
PDF: save with device = cairo_pdf.
p <- plot_forestmap( forestmap_example, es = "smd", vi = "vi", moderators = c( "Population" = "population", "Outcome measure" = "outcome", "Study design" = "design", "Country" = "country" ), rope = c(-0.1, 0.1), y_label = "SMD (95% CI)" ) p # With confidence interval bounds instead of variances dat <- forestmap_example dat$ci_lower <- dat$smd - 1.96 * sqrt(dat$vi) dat$ci_upper <- dat$smd + 1.96 * sqrt(dat$vi) plot_forestmap( dat, es = "smd", lb = "ci_lower", ub = "ci_upper", moderators = c("Population" = "population", "Study design" = "design") ) # Compact layout, Okabe-Ito palette plot_forestmap( forestmap_example, "smd", vi = "vi", moderators = c("Population" = "population", "Study design" = "design"), palette = "okabe_ito", layout = "compact" ) ## Not run: ggplot2::ggsave("forestmap.png", p, width = 7, height = 5.25, dpi = 300) ## End(Not run)p <- plot_forestmap( forestmap_example, es = "smd", vi = "vi", moderators = c( "Population" = "population", "Outcome measure" = "outcome", "Study design" = "design", "Country" = "country" ), rope = c(-0.1, 0.1), y_label = "SMD (95% CI)" ) p # With confidence interval bounds instead of variances dat <- forestmap_example dat$ci_lower <- dat$smd - 1.96 * sqrt(dat$vi) dat$ci_upper <- dat$smd + 1.96 * sqrt(dat$vi) plot_forestmap( dat, es = "smd", lb = "ci_lower", ub = "ci_upper", moderators = c("Population" = "population", "Study design" = "design") ) # Compact layout, Okabe-Ito palette plot_forestmap( forestmap_example, "smd", vi = "vi", moderators = c("Population" = "population", "Study design" = "design"), palette = "okabe_ito", layout = "compact" ) ## Not run: ggplot2::ggsave("forestmap.png", p, width = 7, height = 5.25, dpi = 300) ## End(Not run)