qq_plot: *!!* A QQ-plot for multiple groups

Description Usage Arguments Details Value See Also Examples

View source: R/qq_plot.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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.

distribution

root name of comparison distribution – e.g., "norm" for the normal distribution; t for the t-distribution.

...

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 "|".

Details

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

Value

A ggplot2 object

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)

GegznaV/BioStat documentation built on Aug. 14, 2020, 9:30 p.m.