svgcld-plot
Compact letter display
Which groups differ from which, at a glance?
How to read it
- Read each group's centre and interval.
- Read the letters: the post hoc test could not separate groups that share a letter.
- Groups with no letters in common are.
- Callout 1: The letter above each group.
- Callout 2: Sharing a letter: the test could not separate them.
- Callout 3: Letters are ordered by group, not by size.
Watch out
- Sharing a letter doesn't mean equal: it means the test couldn't separate them.
Defaults
- Sort by the centre (highest first)
- Off
- Sort groups from the highest centre to the lowest.
Pinned in the code
- Draws the engine's numbers as given (precomputed by the Python or R analysis); the chart computes nothing statistical.
- Letters come from the post hoc comparisons (Piepho's insert-and-absorb algorithm): two groups that share any letter are not significantly different at α.
- Intervals are each group's own t interval for its mean, not the simultaneous intervals of the comparisons — the letters, not overlapping bars, carry the test.
- Groups keep the engine's level order unless sorted; letters are assigned from the first level, so sorting does not relabel them.
# Compact letter display — Codesplash Chart Lab (recipe "cld-plot")
# controls: sort=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("cld-plot-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["feed"] = pd.Categorical(df["feed"].astype("string"), categories=["horsebean", "linseed", "soybean", "meatmeal", "casein", "sunflower"])
_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")
LABEL = "feed"
C = "mean weight (g)"
LO = "lower"
HI = "upper"
LET = "letters"
SORT = False # order groups by their centre
d = df.dropna(subset=[LABEL, C]).reset_index(drop=True)
if SORT:
d = d.sort_values(C).reset_index(drop=True)
x = np.arange(len(d))
top = d[HI] if HI else d[C]
fig, ax = plt.subplots(figsize=(8, 4.5))
if LO and HI:
ax.errorbar(x, d[C], yerr=[d[C] - d[LO], d[HI] - d[C]], fmt="none", ecolor=PALETTE[0], capsize=3, linewidth=1.3)
ax.scatter(x, d[C], s=46, color=PALETTE[0], zorder=3)
pad = 0.04 * float(top.max() - (d[LO] if LO else d[C]).min() or 1)
for i, row in d.iterrows(): # groups sharing a letter do not differ significantly
ax.text(i, top[i] + pad, str(row[LET]), ha="center", va="bottom", fontsize=10, fontweight="bold", color=REF)
ax.set_xticks(x, d[LABEL].astype(str))
ax.set_ylabel(C)
ax.margins(y=0.12)
plt.show()Needs pandas, numpy, matplotlib · reads cld-plot-demo.csv · app theme from the optional codesplash helper
# Compact letter display — Codesplash Chart Lab (recipe "cld-plot")
# controls: sort=false
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("cld-plot-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["feed"] = pd.Categorical(df["feed"].astype("string"), categories=["horsebean", "linseed", "soybean", "meatmeal", "casein", "sunflower"])
_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")
LABEL = "feed"
C = "mean weight (g)"
LO = "lower"
HI = "upper"
LET = "letters"
SORT = False
d = df.dropna(subset=[LABEL, C]).reset_index(drop=True)
if SORT:
d = d.sort_values(C).reset_index(drop=True)
err = dict(type="data", symmetric=False, array=d[HI] - d[C], arrayminus=d[C] - d[LO]) if LO and HI else None
fig = go.Figure()
fig.add_scatter(x=d[LABEL].astype(str), y=d[C], mode="markers", error_y=err, marker=dict(size=10, color=PALETTE[0]), showlegend=False)
fig.add_scatter(x=d[LABEL].astype(str), y=d[HI] if HI else d[C], mode="text", text=d[LET].astype(str), textposition="top center",
textfont=dict(size=13, color=REF), showlegend=False)
fig.update_xaxes(categoryorder="array", categoryarray=list(d[LABEL].astype(str)), title=LABEL)
fig.update_yaxes(title=C)
fig.show()Needs pandas, numpy, plotly · reads cld-plot-demo.csv · app theme from the optional codesplash helper
# Compact letter display — Codesplash Chart Lab (recipe "cld-plot")
# controls: sort=false
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("cld-plot-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["feed"]] <- factor(df[["feed"]], levels = c("horsebean", "linseed", "soybean", "meatmeal", "casein", "sunflower"))
df[["letters"]] <- factor(df[["letters"]])
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
label_col <- "feed"
c_col <- "mean weight (g)"
lo_col <- "lower"
hi_col <- "upper"
let_col <- "letters"
sort_groups <- FALSE
d <- df[!is.na(df[[label_col]]) & !is.na(df[[c_col]]), ]
d <- data.frame(lab = as.character(d[[label_col]]), m = d[[c_col]], lo = if (is.null(lo_col)) NA_real_ else d[[lo_col]],
hi = if (is.null(hi_col)) NA_real_ else d[[hi_col]], let = as.character(d[[let_col]]))
d$lab <- factor(d$lab, levels = if (sort_groups) d$lab[order(d$m)] else unique(d$lab))
d$top <- ifelse(is.na(d$hi), d$m, d$hi)
p <- ggplot(d, aes(lab, m)) +
{ if (!all(is.na(d$lo))) geom_errorbar(aes(ymin = lo, ymax = hi), width = 0.15, colour = cs_cat[1]) } +
geom_point(size = 3, colour = cs_cat[1]) +
geom_text(aes(y = top, label = let), vjust = -0.8, fontface = "bold", colour = ref_col) + # shared letter = not significantly different
scale_y_continuous(expand = expansion(mult = c(0.05, 0.15))) + labs(x = label_col, y = c_col) + theme_cs
print(p)Needs ggplot2 · reads cld-plot-demo.csv · app theme from the optional codesplashr helper