Make a quantile comparison plot (qq-plot) for each subset of groups separately using ggplot2 graphics.

qq_plot(
  y,
  data = NULL,
  distribution = "norm",
  ...,
  line = c("quartiles", "robust", "int=0,slope=1", "0,1", "none"),
  envelope = 0.95,
  method = c("mle-normal", "trimmed-normal", "moment-normal", "any"),
  labels = NULL,
  groups = NULL,
  use_colors = FALSE,
  scales = "free",
  sep = " | "
)

Arguments

y

(formula|numeric|character) Either a formula, a numeric vector or a name of a vector in data. If y is a formula (e.g. variable ~ factor), left-hand side provides variable to be summarized. Right-hand side and condition describe subsets. If the left-hand side is empty, right-hand side and condition are shifted over as a convenience.

data

A data frame that contains the variables mentioned in y.

...

Parameters to be passed to function, selected in distribution. In print method, further parameters to function print.

line

(string) A parameter, that controls how reference line is drawn. Options:

  • "0,1" or "int=0,slope=1" to plot a line with intercept = 0 and slope = 1;

  • "quartiles" to pass a line through the quartile-pairs;

  • "robust" for a robust-regression line; the latter uses the rlm function from the MASS package;

  • option "none" is not implemented yet.

envelope

(numeric | FALSE) confidence level for point-wise confidence envelope.

method

(string: "trimmed-normal", "normal", "any"). A method, that controls how estimates of parameters for distribution are computed. Options:

  • "mle-normal" (default) all data values are used to estimate parameters of theoretical normal distribution using method of maximum likelihood;

  • "trimmed-normal" 10\ data values are trimmed before parameters of theoretical normal distribution are estimated using method of moments;

  • "moment-normal" all data values are used to estimate parameters of theoretical normal distribution using method of moments;

  • "any" either parameters are provided manually by user or default parameters are used (if any).

        Options `"mle-normal"`, `"trimmed-normal"` and
        `"moment-normal"` are applicable only if
        `distribution = "norm"`.
        Otherwise `"any"` is selected automatically.
    
groups

(NULL|factor|character)
An alternative way to provide groups. If y is a numeric vector, groups must be a factor (or NULL). If y is a sting, groups must also be a string (or NULL).

use_colors

(logical) use colors for multiple groups

scales

("free"|"free_x"|"free_y"|"fixed") a parmeter to be passed to ggplot2::facet_wrap().

sep

(character) Group name separator if more than one grouping variable is used. default is "|".

Value

A ggplot2 object

Details

Function qq_plot is inspired by qqPlot() in package car (writen by J. Fox).

See also

car::qqPlot() from car package, stats::qqplot() from stats package.

Examples

library(biostat) data(iris) # Formula (no groups): qq_plot(~Sepal.Length, data = iris)
qq_plot("Sepal.Length", data = iris)
# Formula (several groups): qq_plot(Sepal.Length ~ Species, data = iris)
qq_plot(Sepal.Length ~ Species, data = iris, envelope = 0.90)
# Formula (several groups in colors): qq_plot(Sepal.Length ~ Species, data = iris, use_colors = TRUE)
# Vectors (several groups): qq_plot(iris$Sepal.Length, groups = iris$Species)
# For one group: qq_plot("Sepal.Length", data = iris)
qq_plot(~Sepal.Length, data = iris)
qq_plot(iris$Sepal.Length)
# Other examples qq_plot(~weight, data = chickwts)
qq_plot(weight ~ feed, data = chickwts)
qq_plot(uptake ~ Type + Treatment, data = CO2)