e_plot_missing: Plots missing data in a data.frame, possibly grouped by one...

View source: R/e_plot_missing.R

e_plot_missingR Documentation

Plots missing data in a data.frame, possibly grouped by one variable and sorted by a second.

Description

Plots missing data in a data.frame, possibly grouped by one variable and sorted by a second.

Usage

e_plot_missing(
  dat_plot,
  var_group = NULL,
  sw_group_sort = FALSE,
  var2_sort = NULL,
  sw_title_data_name = TRUE,
  sw_text_pct_miss = FALSE,
  sw_complete_by_variable = FALSE
)

Arguments

dat_plot

data.frame or tibble

var_group

variable name to group by (colors data)

sw_group_sort

TRUE/FALSE to sort by grouped variable

var2_sort

second variable name to sort by if data is grouped

sw_title_data_name

TRUE/FALSE to include data object name in title or text string of title to use

sw_text_pct_miss

TRUE/FALSE to include text values of percent missing on bar plot

sw_complete_by_variable

TRUE/FALSE to run e_data_complete_by_variable_subset() to determine which sets of variables result in the most number of complete observations

Value

               ggplot grob plot object

Examples

# Generate missing values
dat_mtcars_miss_e <- dat_mtcars_e
prop_missing <- 0.10
n_missing <-
  sample.int(
    n    = prod(dim(dat_mtcars_miss_e))
  , size = round( prop_missing * prod(dim(dat_mtcars_miss_e)))
  )
ind_missing <- expand.grid(1:dim(dat_mtcars_miss_e)[1], 1:dim(dat_mtcars_miss_e)[2])[n_missing, ]
for (i_row in seq_along(n_missing)) {
  dat_mtcars_miss_e[ind_missing[i_row, 1], ind_missing[i_row, 2] ] <- NA
}

e_plot_missing(
    dat_plot       = dat_mtcars_miss_e
  , var_group      = "cyl"
  , sw_group_sort  = TRUE
  , var2_sort      = "disp"
  )

e_plot_missing(
    dat_plot       = dat_mtcars_miss_e
  , var_group      = "cyl"
  , sw_group_sort  = TRUE
  , var2_sort      = "disp"
  , sw_title_data_name  = "mtcars with random missing values"
  )

erikerhardt/erikmisc documentation built on April 17, 2025, 10:48 a.m.