The goal of ggecdf is to easily create weighted and unweighted empirical cumulative distributions (ECDFs) in ggplot2
You can install the development version of ggecdf from GitHub with:
# install.packages("devtools")
devtools::install_github("malcolmbarrett/ggecdf")
geom_ecdf()
allows you to create ECDFs based on ggplot’s stat_ecdf()
library(ggecdf)
library(ggplot2)
# dataset with weights
nhefs_weights <- tidysmd::nhefs_weights
ggplot(
nhefs_weights,
aes(x = smokeyrs, color = factor(qsmk))
) +
geom_ecdf() +
xlab("Smoking Years") +
ylab("Proportion <= x (unweighted)")
Additionally, geom_ecdf()
supports a weights
aesthetic to calculate
weighted ECDFs. For instance, here’s the same variables weighted by an
ATO weight:
ggplot(
nhefs_weights,
aes(x = smokeyrs, color = factor(qsmk))
) +
geom_ecdf(aes(weights = w_ato)) +
xlab("Smoking Years") +
ylab("Proportion <= x (weighted)")