ggqq_norm: Draw a QQ Plot using ggplot2

View source: R/ggqq_norm.R

ggqq_normR Documentation

Draw a QQ Plot using ggplot2

Description

This function creates a QQ plot (normal probability plot), including a reference line, using ggplot2 graphics. The reference line is based on the normal distribution. The plot may be faceted.

Usage

ggqq_norm(dataframe = NULL, respvar = NULL, facetvars = NULL)

Arguments

dataframe

A data frame containing the variables to be plotted. NA will be omitted by this function.

respvar

Character. The name of the response variable in the data frame.

facetvars

Character. One or two names of the variables to be used for facetting.

Value

A ggplot2 object. This can be printed by print(object) or just object.

Examples

#
### Set up test data
#
set.seed(123)
require("ggplot2")
ns <- 200
#
### Normally distributed data
#
td1 <- data.frame(resp = rnorm(ns),
  f1 = sample(c("A", "B"), ns, replace = TRUE),
  f2 = sample(c("C", "D"), ns, replace = TRUE),
  stringsAsFactors = TRUE)
res <- ggqq_norm(td1, "resp", c("f1", "f2"))
print(res + labs(title = "Normal Distribution"))
#
### Normally distributed data w/ outliers
#
td2 <- td1
bad <- sample(1:ns, 4)
td2$resp[bad[1:2]] <- 5
td2$resp[bad[3:4]] <- -5
res <- ggqq_norm(td2, "resp", c("f1", "f2"))
print(res + labs(title = "Normal Distribution + Outliers"))
#
### Uniformly distributed data
#
td3 <- data.frame(resp = runif(ns),
  f1 = sample(c("A", "B"), ns, replace = TRUE),
  f2 = sample(c("C", "D"), ns, replace = TRUE),
  stringsAsFactors = TRUE)
res <- ggqq_norm(td3, "resp", c("f1", "f2"))
print(res + labs(title = "Uniform Distribution"))


bryanhanson/HandyStuff documentation built on July 22, 2022, 6:18 a.m.