ecdf_plot {esvis}R Documentation

Empirical Cumulative Distribution Plot

Description

This is a wrapper function for the stat_ecdf function and helps make it easy to directly compare distributions at specific locations along the scale.

Usage

ecdf_plot(
  data,
  formula,
  cuts = NULL,
  linewidth = 1.2,
  ref_line_cols = "gray40",
  ref_linetype = "solid",
  center = FALSE,
  ref_rect = TRUE,
  ref_rect_col = "gray40",
  ref_rect_alpha = 0.15
)

Arguments

data

A tidy data frame containing the data to be plotted.

formula

A formula of the type out ~ group where out is the outcome variable and group is the grouping variable. Note this variable can include any arbitrary number of groups. Additional variables can be included with + to produce separate plots by the secondary or tertiary varaible (e.g., out ~ group + characteristic1 + characteristic2). No more than two additional characteristics can be supplied at this time.

cuts

Optional numeric vector stating the location of reference line(s) and/or rectangle(s).

linewidth

Width of ECDF lines. Note that the color of the lines can be controlled through additional functions (e.g., scale_color_brewer, scale_color_manual).

ref_line_cols

Optional vector (or single value) of colors for cuts lines.

ref_linetype

Optional vector (or single value) of line types for cuts lines. Takes any of the arguments supplied by linetype.

center

Logical. Should the functions be centered prior to plotting? Defaults to FALSE. Note that if paneled/faceted plots are produced, the centering occurs by group.

ref_rect

Logical, defaults to TRUE when cuts takes any non-null value. Should semi-transparent rectangle(s) be plotted at the locations of cuts?

ref_rect_col

Color of the fill for the reference rectangles. Defaults to a dark gray.

ref_rect_alpha

Transparency of the fill for the reference rectangles. Defaults to 0.7.

Examples

ecdf_plot(benchmarks, math ~ ell, 
          cuts = c(190, 205, 210), 
          ref_line_cols = c("#D68EE3", "#9BE38E", "#144ECA"))

# Customize the plot with ggplot2 functions
library(ggplot2)
ecdf_plot(benchmarks, math ~ ell, 
          cuts = c(190, 205, 210), 
          ref_line_cols = c("#D68EE3", "#9BE38E", "#144ECA")) +
  theme_minimal() +
  theme(legend.position = "bottom")

ecdf_plot(seda, mean ~ grade) +
  scale_fill_brewer(palette = "Set2") +
  theme_minimal()
  
# Use within the dplyr pipeline
library(dplyr)
benchmarks %>% 
  mutate(season = factor(season, 
                         levels = c("Fall", "Winter", "Spring"))) %>% 
  ecdf_plot(math ~ ell + season + frl)

[Package esvis version 0.3.1 Index]