ggqq_norm | R Documentation |
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.
ggqq_norm(dataframe = NULL, respvar = NULL, facetvars = NULL)
dataframe |
A data frame containing the variables to be plotted. |
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. |
A ggplot2 object. This can be printed by print(object)
or just object
.
# ### 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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.