
Last chance! 50% off unlimited learning
Sale ends in
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.
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
)
A tidy data frame containing the data to be plotted.
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.
Optional numeric vector stating the location of reference line(s) and/or rectangle(s).
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
).
Optional vector (or single value) of colors for
cuts
lines.
Optional vector (or single value) of line types for
cuts
lines. Takes any of the arguments supplied by
linetype.
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.
Logical, defaults to TRUE
when cuts
takes
any non-null value. Should semi-transparent rectangle(s) be plotted at the
locations of cuts
?
Color of the fill for the reference rectangles. Defaults to a dark gray.
Transparency of the fill for the reference rectangles. Defaults to 0.7.
# NOT RUN {
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)
# }
Run the code above in your browser using DataLab