View source: R/spread_level_plot.R
spread_level_plot | R Documentation |
Function produces a scatter plot of median versus spread across a variable's factor levels.
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.
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
)
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 |
plot_log10 |
A logical which if |
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 |
x_title |
A string that sets the x axis title. If |
y_title |
A string that sets the y axis title. If |
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 |
A list object with a data.table and ggplot2 scatter plot.
library(here)
library(data.table)
library(ggplot2)
library(RplotterPkg)
spread_level_lst <- RplotterPkg::spread_level_plot(
df = RplotterPkg::homeruns_2000,
meas_var = "HOMERUNS",
factor_var = "YEARS",
x_title = "Log Median",
y_title = "Log Spread"
)
spread_level_lst$scatter_plot
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.