svgbaujat
Baujat plot
Which studies both create heterogeneity and pull the pooled result?
How to read it
- Read x as a study's contribution to heterogeneity.
- Read y as its influence on the pooled result.
- Top-right studies do both: check them first.
- Callout 1: This study both adds heterogeneity and moves the pooled result.
- Callout 2: Most studies cluster here.
Watch out
- Don't remove a study because it sits here. Find out why it differs.
Defaults
No settings: the chart draws one way.
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.
- x = (yᵢ − θ̂_FE)²/vᵢ; y = (θ̂ − θ̂₍₋ᵢ₎)² / Var(θ̂₍₋ᵢ₎) from leave-one-out fits.
- The four studies furthest from the origin (on axes scaled to their maxima) are labelled.
# Baujat plot — Codesplash Chart Lab (recipe "baujat")
# controls: defaults
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("baujat-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
_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 = "contribution to Q"
Y = "influence on the pooled estimate"
LABEL = "study"
d = df.dropna(subset=[X, Y]).copy()
d["_reach"] = d[X] / d[X].max() + d[Y] / d[Y].max() # distance from the origin on normalized axes
fig, ax = plt.subplots(figsize=(7, 5))
ax.scatter(d[X], d[Y], s=30, color=PALETTE[0])
for _, r in d.nlargest(4, "_reach").iterrows():
ax.annotate(str(r[LABEL]), (r[X], r[Y]), fontsize=8, xytext=(5, 3), textcoords="offset points")
ax.set_xlim(0, d[X].max() * 1.1)
ax.set_ylim(0, d[Y].max() * 1.1)
ax.set_xlabel(X)
ax.set_ylabel(Y)
plt.show()Needs pandas, numpy, matplotlib · reads baujat-demo.csv · app theme from the optional codesplash helper
# Baujat plot — Codesplash Chart Lab (recipe "baujat")
# controls: defaults
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
df = pd.read_csv("baujat-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
_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 = "contribution to Q"
Y = "influence on the pooled estimate"
LABEL = "study"
d = df.dropna(subset=[X, Y]).copy()
d["_reach"] = d[X] / d[X].max() + d[Y] / d[Y].max() # distance from the origin on normalized axes
top = set(d.nlargest(4, "_reach").index)
fig = go.Figure(go.Scatter(x=d[X], y=d[Y], mode="markers+text", marker=dict(size=9, color=PALETTE[0]), textposition="top right",
text=[str(r[LABEL]) if i in top else "" for i, r in d.iterrows()], hovertext=d[LABEL].astype(str)))
fig.update_xaxes(range=[0, d[X].max() * 1.1], title=X)
fig.update_yaxes(range=[0, d[Y].max() * 1.1], title=Y)
fig.show()Needs pandas, numpy, plotly · reads baujat-demo.csv · app theme from the optional codesplash helper
# Baujat plot — Codesplash Chart Lab (recipe "baujat")
# controls: defaults
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))
df <- read.csv("baujat-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["study"]] <- factor(df[["study"]])
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 <- "contribution to Q"
y_col <- "influence on the pooled estimate"
label_col <- "study"
d <- df[!is.na(df[[x_col]]) & !is.na(df[[y_col]]), ]
d$x <- d[[x_col]]; d$y <- d[[y_col]]; d$label <- as.character(d[[label_col]])
reach <- d$x / max(d$x) + d$y / max(d$y) # distance from the origin on normalized axes
top <- d[order(-reach)[seq_len(min(4, nrow(d)))], ]
p <- ggplot(d, aes(x, y)) +
geom_point(colour = cs_cat[1], size = 2.4) +
geom_text(data = top, aes(label = label), size = 2.8, nudge_y = max(d$y) * 0.03) +
coord_cartesian(xlim = c(0, max(d$x) * 1.1), ylim = c(0, max(d$y) * 1.1)) +
labs(x = x_col, y = y_col) + theme_cs
print(p)Needs ggplot2 · reads baujat-demo.csv · app theme from the optional codesplashr helper