stat_qq {ggplot2} | R Documentation |
Calculation for quantile-quantile plot.
stat_qq(mapping = NULL, data = NULL, geom = "point", position = "identity", distribution = qnorm, dparams = list(), na.rm = FALSE, ...)
distribution |
Distribution function to use, if x not specified |
dparams |
Parameters for distribution function |
... |
Other arguments passed to distribution function |
na.rm |
If |
mapping |
The aesthetic mapping, usually constructed
with |
data |
A layer specific dataset - only needed if you want to override the plot defaults. |
geom |
The geometric object to use display the data |
position |
The position adjustment to use for overlappling points on this layer |
a data.frame with additional columns:
sample |
sample quantiles |
theoretical |
theoretical quantiles |
stat_qq
understands the following aesthetics (required aesthetics are in bold):
sample
x
y
# From ?qqplot y <- rt(200, df = 5) qplot(sample = y, stat="qq") # qplot is smart enough to use stat_qq if you use sample qplot(sample = y) qplot(sample = precip) qplot(sample = y, dist = qt, dparams = list(df = 5)) df <- data.frame(y) ggplot(df, aes(sample = y)) + stat_qq() ggplot(df, aes(sample = y)) + geom_point(stat = "qq") # Use fitdistr from MASS to estimate distribution params library(MASS) params <- as.list(fitdistr(y, "t")$estimate) ggplot(df, aes(sample = y)) + stat_qq(dist = qt, dparam = params) # Using to explore the distribution of a variable qplot(sample = mpg, data = mtcars) qplot(sample = mpg, data = mtcars, colour = factor(cyl))