plot_qq: plot_qq

View source: R/plot_qq.R

plot_qqR Documentation

plot_qq

Description

Function plots a quantile-quantile plot (QQ-plot) for comparing an observed distribution with a normal distribution.

Usage

plot_qq(
  df = NULL,
  numeric_col = NULL,
  id_col = NULL,
  standardize = FALSE,
  title = NULL,
  subtitle = NULL,
  x_title = NULL,
  y_title = NULL,
  rot_y_tic_label = FALSE,
  x_limits = NULL,
  x_major_breaks = waiver(),
  x_minor_breaks = waiver(),
  x_labels = waiver(),
  y_limits = NULL,
  y_major_breaks = waiver(),
  y_minor_breaks = waiver(),
  y_labels = waiver(),
  axis_text_size = 11,
  pts_color = "black",
  pts_fill = "white",
  pts_shape = 21,
  pts_stroke = 1,
  pts_alpha = 1,
  pts_size = 1,
  plot_ref_line = TRUE,
  ref_line_color = "red",
  ref_line_width = 1,
  plot_ci_lines = TRUE,
  ci_lines_color = "black",
  ci_lines_width = 1,
  ci_line_type = "solid",
  labels_n = NULL,
  label_color = "red"
)

Arguments

df

A data frame with a column of numeric observations and optionally a column for observation identifications.

numeric_col

A string that names the numeric column from 'df' for QQ plotting.

id_col

An optional argument that names the column from 'df' providing each observation with a unique identification value. If this argument is NULL then row numbers of 'df' are used for identification.

standardize

A logical which if TRUE will standardize the observations under df$numeric_col.

title

A string that sets the plot title.

subtitle

A string that sets the plot subtitle.

x_title

A string that sets the observed response x axis title.

y_title

A string that sets the fitted response y axis title.

rot_y_tic_label

A logical which if TRUE rotates the y tic labels 90 degrees for enhanced readability.

x_limits

Depending on the class of df$numeric_col, a numeric/Date/POSIXct 2 element vector that sets the minimum and maximum for the x axis. Use NA to refer to the existing minimum and maximum.

x_major_breaks

Depending on the class of df$numeric_col, a numeric/Date/POSIXct vector or function that defines the exact major tic locations along the x axis.

x_minor_breaks

Depending on the class of df$numeric_col, a numeric/Date/POSIXct vector or function that defines the exact minor tic locations along the x axis.

x_labels

A character vector with the same length as 'x_major_breaks', that labels the major tics.

y_limits

A numeric 2 element vector that sets the minimum and maximum for the y axis. Use NA to refer to the existing minimum and maximum.

y_major_breaks

A numeric vector or function that defines the exact major tic locations along the y axis.

y_minor_breaks

A numeric vector or function that defines the exact minor tic locations along the y axis.

y_labels

A character vector with the same length as 'y_major_breaks', that labels the major tics.

axis_text_size

A numeric that sets the font size along the axis'. Default is 11.

pts_color

A string that sets the color of the points.

pts_fill

A string that sets the fill color of the points.

pts_shape

A numeric integer that sets the shape of the points. Typical values are 21 “circle”, 22 “square”, 23 “diamond”, 24 “up triangle”, 25 “down triangle”.

pts_stroke

A numeric that sets the drawing width for a point shape.

pts_alpha

A numeric value that sets the alpha level of pts_color.

pts_size

A numeric value that sets the size of the points.

plot_ref_line

A logical which if TRUE will plot a reference line.

ref_line_color

A string that sets the color of the reference line.

ref_line_width

A numeric that sets the reference line width.

plot_ci_lines

A logical which if TRUE will plot upper/lower confidence lines.

ci_lines_color

A string that sets the color of the confidence lines.

ci_lines_width

A numeric that sets the confidence lines width.

ci_line_type

A string that sets confidence lines line type. Acceptable values are twodash, solid, longdash, dotted, dotdash, dashed

labels_n

A numeric that sets the number of extreme values to label. If NULL then no points are labeled.

label_color

A string that sets the label color.

Value

Returning a ggplot2 object.

Examples

library(ggplot2)
library(data.table)
library(RplotterPkg)
library(RregressPkg)

set.seed(20200825)
sample_obs_df <- data.frame(
  vals = stats::rnorm(20, 10, 3)
)

a_plot <- RregressPkg::plot_qq(
  df = sample_obs_df,
  numeric_col = "vals",
  title = "QQ plot of Random Observations",
  subtitle = "Sample is from a normal distribution",
  x_title = "Theoretical Normal Quantiles",
  y_title = "Sample Quantiles",
  rot_y_tic_label = TRUE,
  ci_lines_color = "blue",
  ci_line_type = "dashed",
  pts_size = 4,
  labels_n = 3
)


deandevl/RregressPkg documentation built on Feb. 5, 2025, 12:11 p.m.