svgdrapery
Drapery plot (p-value functions)
At every confidence level at once, which effects are compatible with each study and with the pooled result?
How to read it
- Read each curve as a p-value function: it peaks at p = 1 at the estimate and falls away on both sides.
- Where a curve crosses a horizontal level α, the two crossings are its (1 − α) confidence interval.
- Compare the bold pooled curve with the shaded prediction curve: the second shows where a new study's true effect may land.
- Callout 1: The pooled estimate: p = 1.
- Callout 2: The p = .05 line: crossings give the 95% CI.
- Callout 3: One study's p-value function.
Watch out
- A narrow pooled curve doesn't mean the studies agree; check the prediction curve and the spread of the study curves.
- The p at the null line is not the probability that there is no effect.
Defaults
- Log scale (ratios)
- Off
- Ratios on a log axis so equal ratios look equally far from 1.
- Null value
- 0
- Where 'no effect' sits: 0 for differences, 1 for ratios (dashed).
- Range -1,000,000 to 1,000,000, step 0.1
- Level line (α)
- 0.05
- Draws p = α; where the pooled curve crosses it is the (1 − α) confidence interval.
- Range 0.001 to 0.5, step 0.005
Pinned in the code
- Draws the meta-analysis engine's numbers as given (codesplash.stats.meta_lab in Python ≡ codesplashr in R); the chart computes nothing statistical.
- Each curve is p(θ) = P(|T| ≥ |estimate − θ| / SE): 1 at the estimate, falling on both sides. Studies use the normal distribution; the pooled curve uses z or Knapp–Hartung t; the prediction curve uses SE² + τ² with t on k − 2 df.
- The horizontal dashed line is p = α; the bold segment on it is the pooled (1 − α) interval read off the curve.
# Drapery plot (p-value functions) — Codesplash Chart Lab (recipe "drapery")
# controls: log=false, reference=0, alpha=0.05
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"]
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_DASHES = ["-", (0, (6, 3)), (0, (1.5, 2.5)), (0, (8, 3, 2, 3)), (0, (12, 4)), (0, (3, 3)), (0, (8, 2, 2, 2, 2, 2)), (0, (1.5, 5))]
df = pd.read_csv("drapery-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["kind"] = pd.Categorical(df["kind"].astype("string"), categories=["study", "pooled", "prediction"])
_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")
X = "risk ratio"
P = "p-value"
CURVE = "curve"
KIND = "kind"
LOG, REFERENCE, ALPHA = False, 0, 0.05
d = df.dropna(subset=[X, P])
kind_of = (lambda s: s[KIND].astype(str)) if KIND else (lambda s: pd.Series("study", index=s.index))
fig, ax = plt.subplots(figsize=(7.5, 5))
for name, s in d.groupby(d[CURVE].astype(str), sort=False):
s = s.sort_values(X)
k = kind_of(s).iloc[0]
if k == "prediction":
ax.fill_between(s[X], 0, s[P], color=PALETTE[2], alpha=0.18, lw=0, label="prediction")
ax.plot(s[X], s[P], color=PALETTE[2], alpha=0.6, linewidth=1, linestyle=SERIES_DASHES[2]) # dotted outline, as in the app
elif k == "pooled":
ax.plot(s[X], s[P], color="black", linewidth=2.2, label="pooled", zorder=4)
else:
ax.plot(s[X], s[P], color=PALETTE[0], alpha=0.55, linewidth=1)
ax.axhline(ALPHA, color=REF, linestyle="--", linewidth=1)
ax.text(1.01, ALPHA, f"{100 * (1 - ALPHA):g}% CI", transform=ax.get_yaxis_transform(), va="center", fontsize=8)
ax.axvline(REFERENCE, color=REF, linestyle=":", linewidth=1)
if LOG:
ax.set_xscale("log")
ax.set_ylim(0, 1)
ax.set_xlabel(X)
ax.set_ylabel("p-value")
ax.legend(frameon=False)
plt.show()Needs pandas, numpy, matplotlib · reads drapery-demo.csv · app theme from the optional codesplash helper
# Drapery plot (p-value functions) — Codesplash Chart Lab (recipe "drapery")
# controls: log=false, reference=0, alpha=0.05
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
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 px.colors.qualitative.Plotly
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_DASHES = ["solid", "6px,3px", "1.5px,2.5px", "8px,3px,2px,3px", "12px,4px", "3px,3px", "8px,2px,2px,2px,2px,2px", "1.5px,5px"]
df = pd.read_csv("drapery-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["kind"] = pd.Categorical(df["kind"].astype("string"), categories=["study", "pooled", "prediction"])
_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")
X = "risk ratio"
P = "p-value"
CURVE = "curve"
KIND = "kind"
LOG, REFERENCE, ALPHA = False, 0, 0.05
d = df.dropna(subset=[X, P])
fig = go.Figure()
for name, s in d.groupby(d[CURVE].astype(str), sort=False):
s = s.sort_values(X)
k = str(s[KIND].iloc[0]) if KIND else "study"
if k == "prediction":
fig.add_scatter(x=s[X], y=s[P], mode="lines", fill="tozeroy", line=dict(color=PALETTE[2], width=1, dash=SERIES_DASHES[2]), opacity=0.4, name="prediction") # dotted outline, as in the app
elif k == "pooled":
fig.add_scatter(x=s[X], y=s[P], mode="lines", line=dict(color="black", width=3), name="pooled")
else:
fig.add_scatter(x=s[X], y=s[P], mode="lines", line=dict(color=PALETTE[0], width=1), opacity=0.6, name=name, showlegend=False)
fig.add_hline(y=ALPHA, line_dash="dash", line_color=REF, annotation_text=f"{100 * (1 - ALPHA):g}% CI")
fig.add_vline(x=REFERENCE, line_dash="dot", line_color=REF)
fig.update_layout(xaxis_title=X, yaxis_title="p-value", yaxis_range=[0, 1], xaxis_type="log" if LOG else "linear")
fig.show()Needs pandas, numpy, plotly · reads drapery-demo.csv · app theme from the optional codesplash helper
# Drapery plot (p-value functions) — Codesplash Chart Lab (recipe "drapery")
# controls: log=false, reference=0, alpha=0.05
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
cs_linetypes <- c("solid", "63", "23", "8323", "C4", "33", "822222", "25")
df <- read.csv("drapery-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["curve"]] <- factor(df[["curve"]])
df[["kind"]] <- factor(df[["kind"]], levels = c("study", "pooled", "prediction"))
tok <- if (has_cs) codesplashr::cs_palette(dark = FALSE) else list()
seq_ramp <- if (is.null(tok$sequential)) c("#eff6fd", "#1a469d") else tok$sequential # low → high
div_ramp <- if (is.null(tok$diverging)) c("#c13e2e", "#f3f5f8", "#0859ac") else tok$diverging # −, 0, +
ref_col <- if (is.null(tok$reference)) "#4e5661" else tok$reference
grey_col <- if (is.null(tok$dim)) "#ced1d6" else tok$dim
x_col <- "risk ratio"
p_col <- "p-value"
curve_col <- "curve"
kind_col <- "kind"
log_x <- FALSE; reference <- 0; alpha <- 0.05
d <- df[!is.na(df[[x_col]]) & !is.na(df[[p_col]]), ]
d$x <- d[[x_col]]; d$p <- d[[p_col]]; d$curve <- as.character(d[[curve_col]])
d$kind <- if (!is.null(kind_col)) as.character(d[[kind_col]]) else "study"
d <- d[order(d$curve, d$x), ]
p <- ggplot() +
geom_area(data = d[d$kind == "prediction", ], aes(x, p, group = curve), fill = cs_cat[3], alpha = 0.18) +
geom_line(data = d[d$kind == "prediction", ], aes(x, p, group = curve), colour = cs_cat[3], alpha = 0.6, linetype = cs_linetypes[3]) + # dotted outline, as in the app
geom_line(data = d[d$kind == "study", ], aes(x, p, group = curve), colour = cs_cat[1], alpha = 0.55) +
geom_line(data = d[d$kind == "pooled", ], aes(x, p, group = curve), colour = "black", linewidth = 1.1) +
geom_hline(yintercept = alpha, colour = ref_col, linetype = "dashed") +
geom_vline(xintercept = reference, colour = ref_col, linetype = "dotted") +
annotate("text", x = Inf, y = alpha, label = sprintf("%g%% CI", 100 * (1 - alpha)), hjust = 1.05, vjust = -0.4, size = 3) +
coord_cartesian(ylim = c(0, 1)) +
labs(x = x_col, y = "p-value") + theme_cs
if (log_x) p <- p + scale_x_log10()
print(p)Needs ggplot2 · reads drapery-demo.csv · app theme from the optional codesplashr helper