Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
To make a quantile-quantile (Q-Q) plot in R, call qqnorm(y) followed by qqline(y) from the base stats package to compare a sample with the normal distribution, or use qqplot(x, y) to compare two samples with each other. For a reference distribution other than the normal, or for a plot with a confidence band, use stat_qq() in ggplot2 or qqPlot() in the car package. This guide gives the exact arguments for each route, as they appear in the current R, ggplot2 and car documentation, and explains how to read the result.
What a Q-Q plot is used for in research
A Q-Q plot compares the quantiles of your data with the quantiles of a reference distribution (or of a second sample). If the two share a distribution, the points fall close to a straight line. Researchers use it most often to check whether a variable or a model’s residuals are roughly normal before choosing a parametric test, and to see how they depart from normality (heavy tails, skew, a few extreme values) when a formal test only returns a p-value. The concept itself, including how the quantiles are paired, is covered in What is a Q-Q plot; this page is the R how-to. A Q-Q plot is a diagnostic picture, not a test: it sits alongside, and does not replace, a numerical check such as the Shapiro-Wilk test in R, and both belong to the wider question of normality of distribution.
The same plot goes by several names in searches and tutorials: Q-Q plot, QQ plot, quantile-quantile plot, and the function names qqnorm and qqplot. They all refer to the routes below.
How to install or access it
R itself is distributed from the Comprehensive R Archive Network (CRAN); the steps are in Install R programming. The base routes need nothing further. qqnorm(), qqline() and qqplot() are part of the stats package, which R attaches at startup, so there is nothing to install or load.
The other two routes live in add-on packages, installed once from CRAN and loaded in each session:
install.packages('ggplot2')
install.packages('car')
library(ggplot2)
library(car)
The ggplot2 functions are documented on the tidyverse site (geom_qq reference page) and the car functions in the car reference manual on CRAN; both are listed under Sources.
Step-by-step: draw a Q-Q plot in R
Step 1: a normal Q-Q plot with qqnorm() and qqline()
The documented signature is qqnorm(y, ylim, main = 'Normal Q-Q Plot', xlab = 'Theoretical Quantiles', ylab = 'Sample Quantiles', plot.it = TRUE, datax = FALSE, ...). The R manual’s own example uses simulated t-distributed data:
y = rt(200, df = 5)
qqnorm(y)
qqline(y, col = 2)
- Pass your numeric vector as
y(for residuals from a model,qqnorm(residuals(fit))). - Call
qqline(y)straight after, so the line is drawn on the open plot. Its documented signature isqqline(y, datax = FALSE, distribution = qnorm, probs = c(0.25, 0.75), qtype = 7, ...). - Set
col,main,xlaborylabto label the figure for a report.
With the defaults, sample values go on the y-axis and theoretical quantiles on the x-axis. The datax argument is documented as ‘Should data values be on the x-axis?’, so qqnorm(y, datax = TRUE) swaps the axes (pass the same datax to qqline() so the line matches).
Step 2: compare two samples with qqplot()
Despite the similar name, qqplot() is the two-sample version: qqplot(x, y, plot.it = TRUE, xlab = deparse1(substitute(x)), ylab = deparse1(substitute(y)), ..., conf.level = NULL, conf.args = list(...)). The manual’s example compares two t-distributed samples of different sizes:
y = rt(200, df = 5)
qqplot(y, rt(300, df = 5))
To add a confidence band, set conf.level, for example qqplot(x, y, pch = 19, conf.level = 0.95, conf.args = list(col = 'lightgrey')), then draw the identity line with abline(a = 0, b = 1). The documentation states that an exact confidence band is computed if the product of the sample sizes is less than 10000. Many tutorials describe qqplot() as having no band; the current R documentation lists conf.level, so check that your installed R version includes it (R.version.string, and ?qqplot shows the arguments your version supports).
Step 3: a Q-Q plot in ggplot2
ggplot2 uses a sample aesthetic. The documented example is:
ggplot(mtcars, aes(sample = mpg)) + stat_qq() + stat_qq_line()
stat_qq() and geom_qq() take distribution = stats::qnorm by default and dparams = list() for the distribution’s parameters; stat_qq_line() takes line.p = c(0.25, 0.75) and fullrange = FALSE. Mapping colour = factor(cyl) in the aesthetics gives one set of points per group. To compare against a t distribution instead of the normal, pass distribution = qt and the degrees of freedom through dparams (the reference page’s example uses dparams = params['df']). The reference page notes that distribution is used only when x is not specified.
Step 4: a Q-Q plot with a confidence envelope using car::qqPlot()
The car package’s qqPlot() has the signature qqPlot(x, distribution = 'norm', groups, layout, envelope = TRUE, line = c('quartiles', 'robust', 'none'), id = TRUE, ...). The reference manual (version 3.1-5, dated 2026-01-05) says it includes options not available in qqnorm():
envelopedraws a point-wise confidence envelope:TRUE,FALSEor a confidence level such as0.95.id = TRUElabels the two most extreme points.- A formula method,
qqPlot(variable ~ factor, data = dat), draws a separate plot per group. - For a fitted linear model,
qqPlot(fit)works on the studentized residuals, withdistribution = c('t', 'norm'),line = 'robust', and simulated envelopes (simulate = TRUE,reps = 100) obtained by parametric bootstrap.
Output and how to read it
Read the plot by asking where the points leave the reference line.
- Points track the line closely: the sample is consistent with the reference distribution. Small wobbles at both ends are normal in modest samples; with a confidence envelope, points that stay inside it are not evidence against the reference distribution.
- An S-shaped or curved pattern: the tails are lighter or heavier than the reference, or the sample is skewed. The manual’s example of t-distributed data with 5 degrees of freedom is a heavy-tailed case, which is the pattern to expect when you plot it against the normal.
- One or two points far from the line: candidate outliers.
qqPlot()withid = TRUElabels the two most extreme points so you can find them in your data.
Two details explain why the same data can look slightly different between packages. First, the reference line is not fitted by regression: the base qqline() default is probs = c(0.25, 0.75), the line through the first and third quartiles, ggplot2’s stat_qq_line() uses line.p = c(0.25, 0.75), and qqPlot() chooses between 'quartiles', 'robust' and 'none'. A robust line is fitted with rlm from MASS, so it can differ from the quartile line when the tails are unusual. Second, the base documentation notes that qqnorm() uses ppoints to approximate the expected order statistics, so other software may place the theoretical quantiles slightly differently.
The plotting functions also return their coordinates. qqnorm() and qqplot() return a list with components x and y, and with conf.level set, qqplot() also returns lwr and upr. Use plot.it = FALSE to compute them without drawing, for example to build a custom figure:
q = qqnorm(y, plot.it = FALSE)
str(q)
Pairing the plot with a distribution-based computation helps when you want to know where a theoretical quantile sits; see qnorm in R for the normal quantile function and quantiles in R for computing sample quantiles with quantile().
Which route should you use?
| Situation | Call | Where it comes from |
|---|---|---|
| One sample against the normal, quick check | qqnorm(y); qqline(y) |
stats (base R, already loaded) |
| Two samples against each other, optionally with a band | qqplot(x, y, conf.level = 0.95) |
stats (base R, already loaded) |
| A plot to match other ggplot2 figures, groups by colour | ggplot(d, aes(sample = v)) + stat_qq() + stat_qq_line() |
ggplot2 |
| A non-normal reference distribution in ggplot2 | stat_qq(distribution = qt, dparams = ...) |
ggplot2 |
| Envelope, labelled extreme points, groups, or linear-model residuals | qqPlot(x), qqPlot(v ~ g, data = d), qqPlot(fit) |
car |
All three packages are free to install from CRAN, so the choice is about features and figure style. The argument-by-argument comparison is in the data table below.
Troubleshooting
- The line does not appear.
qqline()adds a line to an existing plot, so call it afterqqnorm(), in the same graphics device. If you useddatax = TRUEinqqnorm(), use it inqqline()too. - ‘could not find function’ for
qqPlotorggplot. The package is not attached. Runinstall.packages()once, thenlibrary(car)orlibrary(ggplot2)in each session. Note the capital P:qqPlot(car) andqqplot(stats) are different functions with different arguments. - ggplot2 draws nothing useful. The variable must be mapped as
aes(sample = ...), notaes(x = ...); thedistributionargument is used only whenxis not specified. conf.levelis rejected byqqplot(). Your R version may predate the argument; check?qqplotand update R if you need the band.- The plot looks non-normal on a large sample. With many observations, small real departures show clearly. Judge the size of the departure, not only its presence, against what your analysis tolerates.
Free alternatives
R is free software, and the options above need only packages from CRAN. If you prefer a different route to the same figure, you can compute the coordinates with qqnorm(y, plot.it = FALSE) and draw them with any plotting function, or use qqPlot() for a single call that includes the envelope. The table below lists the free R routes with what each is best for.
| Option | Strength | Limit documented in the manual |
|---|---|---|
| stats::qqnorm and qqline | No installation; shortest code | Normal reference only; line drawn by a separate call |
| stats::qqplot | Two-sample comparison; optional band through conf.level |
No reference distribution argument; compares two samples |
| ggplot2 stat_qq | Any distribution with a quantile function; groups through aesthetics | Needs the sample aesthetic |
| car::qqPlot | Envelope, point labels, groups, model residuals | Needs the car package |
Frequently asked questions
How do I make a Q-Q plot in R?
Run qqnorm(y) and then qqline(y) on a numeric vector y. Both are in the base stats package, so no installation is needed.
What is the difference between qqnorm and qqplot in R?
qqnorm() plots one sample against the normal distribution. qqplot(x, y) plots two samples against each other. The base R documentation lists them as separate functions with different arguments.
What does it mean if the points are not on the line?
The sample’s quantiles differ from the reference distribution’s. Curvature at the ends points to heavier or lighter tails or skew, and isolated distant points are candidate outliers. It is a visual diagnostic, not a test; pair it with a numerical check such as the Shapiro-Wilk test.
How do I add a confidence band to a Q-Q plot in R?
Use car::qqPlot(), whose envelope argument draws a point-wise confidence envelope, or give qqplot() a conf.level in an R version whose documentation lists it.
How do I make a Q-Q plot in ggplot2?
Map the variable to sample and add stat_qq() and stat_qq_line(): ggplot(mtcars, aes(sample = mpg)) + stat_qq() + stat_qq_line().
Can I compare against a distribution other than the normal?
Yes. In ggplot2 set distribution (for example qt) and dparams; in car::qqPlot() set distribution, and for linear models choose 't' or 'norm'.
Sources
- R Core Team, Quantile-Quantile Plots (qqnorm, qqline, qqplot), R-devel stats manual, read 2026-11-14.
- ggplot2 documentation, A quantile-quantile plot (geom_qq, stat_qq_line), read 2026-11-14.
- Fox, J. and Weisberg, S., car: Companion to Applied Regression, reference manual v3.1-5 (2026-01-05), CRAN, read 2026-11-14.
Data: Q-Q plot routes in R: reference distribution, line and confidence options by function
Compares four R functions that draw Q-Q plots (qqnorm with qqline, qqplot, ggplot2 stat_qq, car qqPlot) by the arguments their official documentation lists for the reference distribution, reference line, confidence band and grouping.
Period covered: 2026.
| Function | Package | Reference distribution | Reference line | Confidence band | Groups |
|---|---|---|---|---|---|
| qqnorm() with qqline() | stats | Normal; qqline has distribution = qnorm | qqline(): probs = c(0.25, 0.75), qtype = 7 | No band argument in the signature | Not an argument |
| qqplot() | stats | None: compares two samples x and y | abline(a = 0, b = 1) in the manual's example | conf.level and conf.args; exact band if product of sample sizes < 10000 | Not an argument |
| stat_qq() with stat_qq_line() | ggplot2 | distribution = stats::qnorm, dparams = list() | line.p = c(0.25, 0.75), fullrange = FALSE | No band argument in the signature | Through aesthetics, e.g. colour = factor(cyl) |
| qqPlot() | car | distribution = 'norm'; 't' or 'norm' for lm objects | line = 'quartiles', 'robust' or 'none' | envelope = TRUE, FALSE or a level such as 0.95 | groups argument and formula method |
Sources
- R stats manual: qqnorm, qqline, qqplot (accessed 2026-11-14)
- ggplot2: geom_qq and stat_qq_line (accessed 2026-11-14)
- car reference manual v3.1-5 (accessed 2026-11-14)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







