Skip to content
svgforest-meta

Meta-analysis forest plot

How do the studies' effects compare, and what is the pooled effect and its spread?

Demo data · seed 20261101 · 11 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read each row as a study: square for estimate (larger means more weight), line for interval.
  2. Read the diamond at the bottom as the pooled estimate.
  3. Compare the rows' scatter with their intervals: more scatter than expected means heterogeneity.
  1. Callout 1: One study: square and interval.
  2. Callout 2: The diamond: the pooled estimate.
  3. Callout 3: Reference line: no effect.

Watch out

  • A pooled number can hide real differences between studies. Read the prediction interval too.

Defaults

Reference (null) value
0
Where 'no effect' sits: 0 for differences, 1 for ratios.
Range -1,000 to 1,000, step 0.1
Log scale (ratios)
Off
Ratios on a log axis so equal ratios look equally far from 1.

Pinned in the code

  • Draws the meta-analysis engine's numbers as given (codesplash.stats.meta in Python ≡ codesplashr in R); the chart computes nothing statistical.
  • Studies keep the engine's order; the pooled row (kind = summary) is drawn as a diamond spanning its confidence interval.
  • Marker area ∝ the study's weight in the pooled estimate (inverse variance, including τ² for random effects).
  • The dashed line through the diamond is the prediction interval (engine controls piLow/piHigh): where a new study's true effect is expected.
  • Ratios are back-transformed from the log scale and drawn on a log axis with the reference at 1.
# Meta-analysis forest plot — Codesplash Chart Lab (recipe "forest-meta")
# controls: reference=0, log=false
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("forest-meta-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["study"] = pd.Categorical(df["study"].astype("string"), categories=["Aronson 1948", "Ferguson 1949", "Rosenthal 1960", "Hart 1977", "Frimodt 1973", "Stein 1953", "Vandiviere 1973", "Madras 1980", "Coetzee 1968", "Rosenthal 1961", "Pooled (RE)"])
df["row"] = pd.Categorical(df["row"].astype("string"), categories=["study", "summary"])

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
def fmt(v):
    """Number on a forest row, as in the app."""
    if v is None or not np.isfinite(v):
        return "—"
    return f"{v:.0f}" if abs(v) >= 100 else f"{v:.1f}" if abs(v) >= 10 else f"{v:.2f}"
LABEL = "study"
EST = "risk ratio"
LOW = "low"
HIGH = "high"
WEIGHT = "weight %"
KIND = "row"
LOG, REFERENCE = False, 0  # the "no effect" value: 0 for differences, 1 for ratios
d = df.dropna(subset=[EST]).reset_index(drop=True)
y = np.arange(len(d))[::-1]  # first row at the top
summary = d[KIND].astype(str).eq("summary") if KIND else pd.Series(False, index=d.index)
w = pd.to_numeric(d[WEIGHT], errors="coerce") if WEIGHT else pd.Series(np.nan, index=d.index)
PI_LOW, PI_HIGH = None, None  # the prediction interval, when the result has one
w_max = w[~summary].max()
fig, ax = plt.subplots(figsize=(8.5, max(3, 0.34 * len(d) + 1.2)))
ax.axvline(REFERENCE, color=REF, linestyle="--", linewidth=1)
for i, row in d.iterrows():
    yi = y[i]
    note = f"{fmt(row[EST])} [{fmt(row[LOW])}, {fmt(row[HIGH])}]"
    if summary[i]:
        if PI_LOW is not None:
            ax.plot([PI_LOW, PI_HIGH], [yi, yi], color=REF, linestyle=":", linewidth=1.4)
        ax.fill([row[LOW], row[EST], row[HIGH], row[EST]], [yi, yi + 0.32, yi, yi - 0.32], color=plt.rcParams["text.color"], zorder=3)
    else:
        ax.plot([row[LOW], row[HIGH]], [yi, yi], color=PALETTE[0], linewidth=1.4)
        size = 4 + 10 * np.sqrt(max(0, w[i]) / w_max) if np.isfinite(w[i]) and w_max > 0 else 7
        ax.plot(row[EST], yi, marker="s", markersize=size, color=PALETTE[0], linestyle="none", zorder=3)
        if np.isfinite(w[i]):
            note += f"  {w[i]:.1f}%"
    ax.text(1.01, yi, note, transform=ax.get_yaxis_transform(), va="center", fontsize=8, fontweight="bold" if summary[i] else "normal")
if LOG:
    ax.set_xscale("log")
ax.set_yticks(y, d[LABEL].astype(str))
ax.set_ylim(-0.7, len(d) - 0.3)
ax.set_xlabel(EST)
fig.tight_layout()
fig.subplots_adjust(right=0.74)
plt.show()

Needs pandas, numpy, matplotlib · reads forest-meta-demo.csv · app theme from the optional codesplash helper