svgprofile-plot
Profile plot
Do the groups' mean profiles run parallel across the measures, at the same level, and is the common profile flat?
How to read it
- Read each line as a group's means across measures.
- Parallel lines: the same shape, possibly at different levels.
- Non-parallel lines: the groups change differently.
- Callout 1: Lines run roughly parallel here.
- Callout 2: The vertical gap: the level difference.
- Callout 3: Measures need a common scale.
Watch out
- Measures on different scales make the shapes meaningless.
Defaults
- Show intervals
- On
- Add confidence intervals at each point.
Pinned in the code
- Draws the engine's group means as given, in the measures' order; intervals are each mean's own t interval (not simultaneous, and not the test).
- Groups are dodged slightly so overlapping intervals stay visible; lines connect consecutive measures only.
- Profile analysis tests parallelism (equal successive differences), levels (equal group averages) and flatness (equal measure averages) — the plot shows all three at once.
# Profile plot — Codesplash Chart Lab (recipe "profile-plot")
# controls: intervals=true
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))]
SERIES_MARKERS = ["o", "s", "^", "D", "P", "*", "2", "v"]
df = pd.read_csv("profile-plot-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["measure"] = pd.Categorical(df["measure"].astype("string"), categories=["hour 1", "hour 2", "hour 3", "hour 4", "hour 5"])
df["treatment"] = pd.Categorical(df["treatment"].astype("string"), categories=["control", "A", "B"])
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
M = "measure"
V = "mean score"
G = "treatment"
LO = "CI low"
HI = "CI high"
measures = levels_of(df[M])
pos = {m: i for i, m in enumerate(measures)}
fig, ax = plt.subplots(figsize=(7, 4.5))
ks = levels_of(df[G]) if G else ["all"]
many = len(ks) > 1 # several groups: dash and marker shape per profile, as in the app
for i, k in enumerate(ks):
g = (df[df[G].astype(str) == str(k)] if G else df).copy()
g["_x"] = g[M].astype(str).map(pos)
g, col = g.sort_values("_x"), PALETTE[i % len(PALETTE)]
ax.plot(g["_x"], g[V], marker=SERIES_MARKERS[i % 8] if many else "o", linestyle=SERIES_DASHES[i % 8] if many else "-", color=col, label=str(k))
if LO and HI:
ax.vlines(g["_x"], g[LO], g[HI], color=col, alpha=0.6)
ax.set_xticks(range(len(measures)), measures)
ax.set_xlabel(M)
ax.set_ylabel(V)
if G:
ax.legend(title=G, fontsize=8)
plt.show()Needs pandas, numpy, matplotlib · reads profile-plot-demo.csv · app theme from the optional codesplash helper
# Profile plot — Codesplash Chart Lab (recipe "profile-plot")
# controls: intervals=true
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"]
SERIES_MARKERS = ["circle", "square", "triangle-up", "diamond", "cross", "star", "y-up", "triangle-down"]
df = pd.read_csv("profile-plot-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["measure"] = pd.Categorical(df["measure"].astype("string"), categories=["hour 1", "hour 2", "hour 3", "hour 4", "hour 5"])
df["treatment"] = pd.Categorical(df["treatment"].astype("string"), categories=["control", "A", "B"])
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
M = "measure"
V = "mean score"
G = "treatment"
LO = "CI low"
HI = "CI high"
measures = levels_of(df[M])
fig = go.Figure()
ks = levels_of(df[G]) if G else ["all"]
many = len(ks) > 1 # several groups: dash and marker shape per profile, as in the app
for i, k in enumerate(ks):
g = df[df[G].astype(str) == str(k)] if G else df
g = g.set_index(g[M].astype(str)).reindex(measures)
err = dict(type="data", array=g[HI] - g[V], arrayminus=g[V] - g[LO]) if LO and HI else None
fig.add_scatter(x=measures, y=g[V], mode="lines+markers", name=str(k), line=dict(color=PALETTE[i % len(PALETTE)], dash=SERIES_DASHES[i % 8] if many else "solid"), marker=dict(symbol=SERIES_MARKERS[i % 8] if many else "circle", size=8), error_y=err)
fig.update_layout(xaxis_title=M, yaxis_title=V)
fig.show()Needs pandas, numpy, plotly · reads profile-plot-demo.csv · app theme from the optional codesplash helper
# Profile plot — Codesplash Chart Lab (recipe "profile-plot")
# controls: intervals=true
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")
cs_shapes <- c(16, 15, 17, 18, 3, 8, 4, 25)
df <- read.csv("profile-plot-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["measure"]] <- factor(df[["measure"]], levels = c("hour 1", "hour 2", "hour 3", "hour 4", "hour 5"))
df[["treatment"]] <- factor(df[["treatment"]], levels = c("control", "A", "B"))
levels_of <- function(v) if (is.factor(v)) levels(droplevels(v)) else unique(as.character(v[!is.na(v)]))
M <- "measure"
V <- "mean score"
G <- "treatment"
LO <- "CI low"
HI <- "CI high"
d <- data.frame(m = factor(as.character(df[[M]]), levels = levels_of(df[[M]])), v = df[[V]], g = if (is.null(G)) "all" else as.character(df[[G]]))
if (!is.null(LO) && !is.null(HI)) { d$lo <- df[[LO]]; d$hi <- df[[HI]] }
p <- ggplot(d, aes(m, v, colour = g, group = g, linetype = g, shape = g)) + # dash and marker shape per profile, as in the app
geom_line() + geom_point(size = 2) +
(if (!is.null(LO) && !is.null(HI)) geom_linerange(aes(ymin = lo, ymax = hi), alpha = 0.6)) +
scale_colour_manual(values = cs_cat, name = G) + scale_linetype_manual(values = cs_linetypes, name = G) + scale_shape_manual(values = cs_shapes, name = G) +
labs(x = M, y = V) + theme_cs
print(p)Needs ggplot2 · reads profile-plot-demo.csv · app theme from the optional codesplashr helper