← All tutorials

Manhattan Plot Tutorial: qqman in R, Python, SPSS and a Free Online Tool

Updated November 7, 2026 · StatFAS Tutorials · Beginner to intermediate

This tutorial shows how to create a Manhattan plot and run the statistics behind the Manhattan plot in four ways: SPSS, R, Python and the free Manhattan Plot Maker on statfas.com. Every script is complete and can be copied into the software. For the concepts behind the Manhattan plot, read the guide Manhattan Plot Explained: GWAS Meaning, Significance Lines and Interpretation.

Step 1: Prepare the data

One row per SNP with the columns SNP (optional), CHR, BP (base-pair position) and P (p value). Chromosomes X and Y are accepted. Files with tens of thousands of SNPs work in the browser.

Example layout:

SNP,CHR,BP,P
rs1000123,1,1043210,0.4210
rs1000456,1,1050873,0.0031
rs2001987,7,60012345,3.1e-12

Step 2: SPSS

SPSS has no Manhattan plot procedure and no GWAS engine. Association testing is usually done in PLINK, REGENIE or similar software; SPSS can then compute −log10 p, the inflation factor and a scatter plot of the results.

* Data: SNP, CHR, BP, P from PLINK or another GWAS program.
COMPUTE negLog10P = -LG10(P).
COMPUTE chi2 = IDF.CHISQ(1 - P, 1).
EXECUTE.
* Genomic inflation factor: median of chi2 divided by 0.4549.
FREQUENCIES VARIABLES=chi2 /FORMAT=NOTABLE /PERCENTILES=50.

* Cumulative position so chromosomes sit side by side:
AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=CHR /chrMax=MAX(BP).
* Add the sum of the maxima of all earlier chromosomes (shift in a small lookup table), then:
* COMPUTE xpos = BP + offset.
GRAPH /SCATTERPLOT(BIVAR)=xpos WITH negLog10P BY CHR.
* Add a reference line at 7.3 (= -log10(5e-8)) in the Chart Editor (Options > Y Axis Reference Line).

Step 3: R

The qqman package draws the Manhattan plot and the QQ plot in two lines; the inflation factor takes one more.

library(qqman)
gwas <- read.csv("gwas.csv")                                 # columns: SNP, CHR, BP, P
lambda <- median(qchisq(1 - gwas$P, df = 1)) / qchisq(0.5, df = 1)   # genomic inflation
lambda

png("manhattan.png", width = 3000, height = 1350, res = 300)
manhattan(gwas, chr = "CHR", bp = "BP", p = "P", snp = "SNP",
          genomewideline = -log10(5e-8), suggestiveline = -log10(1e-5),
          col = c("#1f4e79", "#7fa8d1"), annotatePval = 1e-8)
dev.off()
qq(gwas$P)                                                   # companion QQ plot

Step 4: Python

The code below builds cumulative genomic positions, draws the Manhattan plot with Matplotlib and calculates λ with SciPy.

import numpy as np, pandas as pd
import matplotlib.pyplot as plt
from scipy import stats

df = pd.read_csv("gwas.csv").sort_values(["CHR", "BP"])    # columns: SNP, CHR, BP, P
offset = df.groupby("CHR")["BP"].max().cumsum().shift(fill_value=0)
df["x"] = df["BP"] + df["CHR"].map(offset)
df["y"] = -np.log10(df["P"])

lam = np.median(stats.chi2.isf(df["P"], 1)) / stats.chi2.ppf(0.5, 1)   # genomic inflation
print(f"lambda = {lam:.3f}; SNPs below 5e-8: {(df['P'] < 5e-8).sum()}")

plt.figure(figsize=(10, 4.5))
plt.scatter(df["x"], df["y"], s=3, c=np.where(df["CHR"] % 2 == 0, "#1f4e79", "#7fa8d1"))
plt.axhline(-np.log10(5e-8), c="red", ls="--", lw=0.9)
plt.axhline(-np.log10(1e-5), c="blue", ls="--", lw=0.9)
mid = df.groupby("CHR")["x"].median()
plt.xticks(mid.values, mid.index.astype(str), fontsize=8)
plt.xlabel("Chromosome"); plt.ylabel("-log10(p)"); plt.tight_layout()
plt.savefig("manhattan.png", dpi=300)

Step 5: The easy way on statfas.com

The Manhattan Plot Maker needs no installation and no code. Follow these steps:

  1. Open the tool. Go to the StatFAS Manhattan Plot Maker.
  2. Add data. Click Load example data to see the layout, then paste or upload SNP, CHR, BP and P columns.
  3. Set thresholds. Choose the genome-wide and suggestive p value lines, the locus window in kilobases, the label count and the colours.
  4. Read the results. The tool calculates λ, the Bonferroni threshold, the number of significant SNPs and independent loci, and draws the Manhattan plot.
  5. Download. Download the PNG or SVG, or a Word file with the figure, the tables and the APA 7 interpretation.
Try the Manhattan Plot Maker free
Upload or paste data and get the Manhattan plot, the statistics and an APA 7 write-up in seconds.
Open the free Manhattan Plot Maker

Step 6: Interpret and report in APA 7

Check these points before the Manhattan plot goes into a manuscript:

Example APA 7 results paragraph:

A genome-wide association analysis of 20,146 SNPs was summarised in a Manhattan plot. The genomic inflation factor was λ = 1.01. Four independent loci exceeded the genome-wide threshold (p < 5 × 10⁻⁸); the strongest association was rs6433610 on chromosome 7 (p = 1.35 × 10⁻¹³; Figure 1).

Avoid these mistakes with the Manhattan plot:

Frequently asked questions

What does a Manhattan plot show?

A Manhattan plot shows the −log10 p value of every tested SNP across the genome, ordered by chromosome and position. Towers above the significance line mark associated regions.

Why is the threshold 5 × 10⁻⁸?

The threshold is a Bonferroni-style correction for roughly one million independent common-variant tests in European-ancestry genomes (0.05 divided by 1,000,000).

What is the genomic inflation factor?

The genomic inflation factor λ is the median observed χ² statistic divided by the expected median (0.455). Values near 1 suggest calibrated tests.

What is the difference between a Manhattan plot and a QQ plot?

A Manhattan plot shows where associations lie in the genome. A QQ plot compares observed with expected p values and diagnoses inflation.

Related guides

How to cite this page: StatFAS. (2026, November 7). Manhattan Plot Tutorial: qqman in R, Python, SPSS and a Free Online Tool. https://statfas.com/tutorials/manhattan-plot.html