Mutation Lollipop Plot Tutorial: R, Python, SPSS and Free Online Tool
Updated November 7, 2026 · StatFAS Tutorials · Beginner to intermediate
This tutorial shows how to create a mutation lollipop plot and run the statistics behind the mutation lollipop plot in four ways: SPSS, R, Python and the free Mutation Lollipop Plot Maker on statfas.com. Every script is complete and can be copied into the software. For the concepts behind the mutation lollipop plot, read the guide Mutation Lollipop Plot Explained: Hotspots, Protein Domains and Interpretation.
Step 1: Prepare the data
One row per mutation (or per mutated position) with Position (amino-acid number), Type (missense, nonsense, frameshift, splice, …), an optional Count and an optional Change label such as R175H. Enter the protein length and domains (Name, start, end) in the options.
Example layout:
Position,Change,Type,Count
175,R175H,Missense,46
248,R248Q,Missense,38
213,R213*,Nonsense,9Step 2: SPSS
SPSS has no lollipop plot, but a thin-bar chart approximates the picture and the Poisson and binomial functions (CDF.POISSON, CDF.BINOM) compute hotspot and domain tests.
* Variables: Position, Count (one row per mutated position). N = total mutations, L = protein length.
AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK= /M=SUM(Count).
COMPUTE L = 393.
COMPUTE w = 10.
COMPUTE expected = M * w / L.
* Observed count in a window (for example residues 170-179) = sum of Count where Position is in that window, then:
COMPUTE pWindow = 1 - CDF.POISSON(obs - 1, expected).
* Domain test: k = mutations inside the domain, pDomain = (292 - 102 + 1) / L.
COMPUTE pBinom = 1 - CDF.BINOM(k - 1, M, pDomain).
EXECUTE.
* Plot: Graphs > Chart Builder > Bar > Simple Bar (thin bars) with Position on X and Count on Y approximates a lollipop plot.Step 3: R
ggplot2 draws the mutation lollipop plot with geom_segment() and geom_point(); base R functions supply the Poisson and binomial tests. The trackViewer and g3viz packages offer ready-made lollipop plots.
library(ggplot2)
mut <- read.csv("mutations.csv") # columns: Position, Type, Count
L <- 393 # protein length (amino acids)
pos <- aggregate(Count ~ Position, mut, sum)
ggplot(pos, aes(Position, Count)) +
geom_segment(aes(xend = Position, yend = 0), colour = "grey35") +
geom_point(size = 2.5, colour = "#1f77b4") +
annotate("rect", xmin = 102, xmax = 292, ymin = -2, ymax = 0, fill = "#ffd92f") +
xlim(0, L) + labs(x = "Amino-acid position", y = "Mutations") + theme_classic()
ggsave("lollipop.png", width = 9, height = 4, dpi = 300)
# Hotspot scan: Poisson upper tail for each 10-residue window
M <- sum(pos$Count); w <- 10
counts <- numeric(L); counts[pos$Position] <- pos$Count
obs <- sapply(1:(L - w + 1), function(s) sum(counts[s:(s + w - 1)]))
p <- ppois(obs - 1, M * w / L, lower.tail = FALSE)
head(order(p), 5); p.adjust(p, "BH")[order(p)][1:5]
# Domain enrichment: exact binomial test
k <- sum(counts[102:292])
binom.test(k, M, p = (292 - 102 + 1) / L, alternative = "greater")$p.value
# Ready-made alternatives: trackViewer::lollipopPlot, g3vizStep 4: Python
Matplotlib draws the stems and circles; SciPy provides the Poisson and binomial tests for hotspots and domains.
import numpy as np, pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import poisson, binom
mut = pd.read_csv("mutations.csv") # columns: Position, Type, Count
L = 393 # protein length (amino acids)
per_pos = mut.groupby("Position")["Count"].sum()
M, w = per_pos.sum(), 10
plt.figure(figsize=(9, 4))
plt.vlines(per_pos.index, 0, per_pos.values, color="#555", lw=1)
plt.scatter(per_pos.index, per_pos.values, s=25, color="#1f77b4", zorder=3)
plt.axvspan(102, 292, ymin=-0.05, ymax=0, color="#ffd92f", clip_on=False) # domain track
plt.xlim(0, L); plt.xlabel("Amino-acid position"); plt.ylabel("Mutations")
plt.tight_layout(); plt.savefig("lollipop.png", dpi=300)
# Hotspot scan: sliding window, Poisson upper tail under uniform expectation
counts = np.zeros(L + 1); counts[per_pos.index.values] = per_pos.values
scan = pd.DataFrame({"start": range(1, L - w + 2)})
scan["obs"] = [counts[s:s + w].sum() for s in scan["start"]]
scan["p"] = poisson.sf(scan["obs"] - 1, M * w / L)
print(scan.sort_values("p").head())
# Domain enrichment: exact binomial test (domain 102-292)
k = per_pos[(per_pos.index >= 102) & (per_pos.index <= 292)].sum()
print("DNA-binding domain p =", binom.sf(k - 1, M, (292 - 102 + 1) / L))Step 5: The easy way on statfas.com
The Mutation Lollipop Plot Maker needs no installation and no code. Follow these steps:
- Open the tool. Go to the StatFAS Mutation Lollipop Plot Maker.
- Add data. Click Load example data to see the layout and the domain list, then paste or upload your mutation table.
- Enter protein details. Type the gene name, the protein length, the domains (Name, start, end) and the hotspot window size.
- Read the results. The tool draws the mutation lollipop plot, counts mutation types, scans for hotspots with a Poisson test and tests domain enrichment with exact binomial tests.
- Download. Download the PNG or SVG, or a Word file with the figure, three tables and the APA 7 interpretation.
Upload or paste data and get the mutation lollipop plot, the statistics and an APA 7 write-up in seconds.
Open the free Mutation Lollipop Plot Maker
Step 6: Interpret and report in APA 7
Check these points before the mutation lollipop plot goes into a manuscript:
- Tall sticks indicate recurrent mutations. Recurrence at the same residue is stronger evidence for selection than scattered single mutations.
- Judge hotspots statistically. A sliding-window Poisson test compares the observed count in a window with the count expected if mutations were spread uniformly along the protein, with correction for the number of windows.
- Test domains with an exact binomial test: the expected share of mutations in a domain equals the share of the protein length that the domain covers.
- Distinguish mutation types by colour: clusters of missense variants point to gain of function or altered interfaces, scattered truncating variants point to loss of function.
Example APA 7 results paragraph:
Avoid these mistakes with the mutation lollipop plot:
- Declaring hotspots by eye without a statistical test or multiple-testing correction.
- Mixing transcript versions, so that positions do not match the domain coordinates.
- Plotting counts without reporting the cohort size.
- Ignoring hypermutated samples that dominate the counts.
Frequently asked questions
What does a mutation lollipop plot show?
A mutation lollipop plot shows the position of mutations along a protein, with stick height for the number of mutations and colour for the mutation type, usually with a domain track below.
How do I find mutation hotspots?
Count mutations in sliding windows and compare each window with the expected count under a uniform distribution using a Poisson test, then correct for the number of windows.
What is a protein domain track?
The domain track draws functional regions (for example a DNA-binding domain) as boxes along the protein axis, taken from databases such as UniProt or Pfam.
Can a lollipop plot be used for nucleotide positions?
Yes. The same plot works for nucleotide positions of a gene or for genomic coordinates, as long as positions and domain coordinates use the same reference.
Related guides
How to cite this page: StatFAS. (2026, November 7). Mutation Lollipop Plot Tutorial: R, Python, SPSS and Free Online Tool. https://statfas.com/tutorials/mutation-lollipop-plot.html