spread_level_plot: Function produces a scatter plot of median versus spread...

View source: R/spread_level_plot.R

spread_level_plotR Documentation

Function produces a scatter plot of median versus spread across a variable's factor levels.

Description

The spread is defined as the difference between the 75th and 25th quartiles. Function returns a named list with a data.table of each level's median, quartile values, and a ggplot2 scatter plot with medians along the x axis and spreads along the y axis.

Usage

spread_level_plot(
  df,
  meas_var,
  factor_var,
  plot_line_fit = TRUE,
  plot_log10 = TRUE,
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  center_titles = FALSE,
  x_title = "Median",
  y_title = "Spread",
  x_limits = NULL,
  x_major_breaks = waiver(),
  y_limits = NULL,
  y_major_breaks = waiver(),
  label_pts = TRUE
)

Arguments

df

The required target data frame with a measure variable and a factor variable with multiple levels.

meas_var

A required string that names the measure variable from df.

factor_var

A required string that names the factor variable from df.

plot_line_fit

A logical which if TRUE plots a line fit between median and spread values.

plot_log10

A logical which if TRUE will plot log10 values of median versus spread instead of raw values.

title

A string that sets the plot title.

subtitle

A string that sets the plot subtitle.

caption

A string that sets the plot caption

center_titles

A logical which if TRUE centers both the title and subtitle.

x_title

A string that sets the x axis title. If NULL then the x axis title does not appear.

y_title

A string that sets the y axis title. If NULL then the y axis title does not appear.

x_limits

A numeric 2 element vector that sets the minimum and maximum for the x axis.

x_major_breaks

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

y_limits

A numeric 2 element vector that sets the minimum and maximum for the y axis.

y_major_breaks

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

label_pts

A logical which if TRUE will label the plot points.

Value

A named list object with a data.table and ggplot2 scatter plot.

Author(s)

Rick Dean


deandevl/RplotterPkg documentation built on Feb. 1, 2024, 8:02 p.m.