| Title: | Visualizations for 'mice' with 'ggplot2' |
|---|---|
| Description: | Enhance a 'mice' imputation workflow with visualizations for incomplete and/or imputed data. The plotting functions produce 'ggplot' objects which may be easily manipulated or extended. Use 'ggmice' to inspect missing data, develop imputation models, evaluate algorithmic convergence, or compare observed versus imputed data. |
| Authors: | Hanne Oberman [aut, cre] (ORCID: <https://orcid.org/0000-0003-3276-2141>), Utrecht University [fnd], University Medical Centre Utrecht [fnd], Thom Volker [ctb] (ORCID: <https://orcid.org/0000-0002-2408-7820>), Gerko Vink [ctb] (ORCID: <https://orcid.org/0000-0001-9767-1924>), Pepijn Vink [ctb] (ORCID: <https://orcid.org/0000-0001-6960-9904>), Jamie Wallis [ctb] (ORCID: <https://orcid.org/0000-0003-2765-3813>), Kyle Lang [ctb] (ORCID: <https://orcid.org/0000-0001-5340-7849>) |
| Maintainer: | Hanne Oberman <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.1.9000 |
| Built: | 2026-06-01 21:23:49 UTC |
| Source: | https://github.com/amices/ggmice |
Box-and-whisker plot of observed and imputed data
bwplot(...)bwplot(...)
... |
Any arguments passed to the function. |
The output of mice::bwplot and a message about the ggmice equivalent.
imp <- mice::mice(mice::nhanes, maxit = 1, printFlag = FALSE) bwplot(imp)imp <- mice::mice(mice::nhanes, maxit = 1, printFlag = FALSE) bwplot(imp)
Densityplot of observed and imputed data
densityplot(...)densityplot(...)
... |
Any arguments passed to the function. |
The output of mice::densityplot and a message about the ggmice equivalent.
imp <- mice::mice(mice::nhanes, maxit = 1, printFlag = FALSE) densityplot(imp)imp <- mice::mice(mice::nhanes, maxit = 1, printFlag = FALSE) densityplot(imp)
Plot incomplete or imputed data
ggmice(data = NULL, mapping = ggplot2::aes())ggmice(data = NULL, mapping = ggplot2::aes())
data |
An incomplete dataset (of class |
mapping |
A list of aesthetic mappings created with |
An object of class ggplot2::ggplot. The ggmice function returns output
equivalent to ggplot2::ggplot output, with a few important exceptions:
The theme is set to theme_mice.
The color scale is set to the mice::mdc colors.
The colour aesthetic is set to .where, an internally defined variable which distinguishes
observed data from missing data or imputed data (for incomplete and imputed data, respectively).
See the ggmice vignette to use the ggmice() function on
incomplete data
or imputed data.
dat <- mice::nhanes ggmice(dat, ggplot2::aes(x = age, y = bmi)) + ggplot2::geom_point() imp <- mice::mice(dat, print = FALSE) ggmice(imp, ggplot2::aes(x = age, y = bmi)) + ggplot2::geom_point()dat <- mice::nhanes ggmice(dat, ggplot2::aes(x = age, y = bmi)) + ggplot2::geom_point() imp <- mice::mice(dat, print = FALSE) ggmice(imp, ggplot2::aes(x = age, y = bmi)) + ggplot2::geom_point()
Plot correlations between (incomplete) variables
plot_corr( data, vrb = "all", label = FALSE, square = TRUE, diagonal = FALSE, rotate = FALSE, caption = TRUE )plot_corr( data, vrb = "all", label = FALSE, square = TRUE, diagonal = FALSE, rotate = FALSE, caption = TRUE )
data |
A dataset of class |
vrb |
String, vector, or unquoted expression with variable name(s), default is "all". |
label |
Logical indicating whether correlation values should be displayed. |
square |
Logical indicating whether the plot tiles should be squares. |
diagonal |
Logical indicating whether the correlation of each variable with itself should be displayed. |
rotate |
Logical indicating whether the variable name labels should be rotated 90 degrees. |
caption |
Logical indicating whether the figure caption should be displayed. |
An object of class ggplot2::ggplot.
# plot correlations for all columns plot_corr(mice::nhanes) # plot correlations for specific columns by supplying a character vector plot_corr(mice::nhanes, c("chl", "hyp")) # plot correlations for specific columns by supplying unquoted variable names plot_corr(mice::nhanes, c(chl, hyp)) # plot correlations for specific columns by passing an object with variable names # from the environment, unquoted with `!!` my_variables <- c("chl", "hyp") plot_corr(mice::nhanes, !!my_variables) # object with variable names must be unquoted with `!!` try(plot_corr(mice::nhanes, my_variables))# plot correlations for all columns plot_corr(mice::nhanes) # plot correlations for specific columns by supplying a character vector plot_corr(mice::nhanes, c("chl", "hyp")) # plot correlations for specific columns by supplying unquoted variable names plot_corr(mice::nhanes, c(chl, hyp)) # plot correlations for specific columns by passing an object with variable names # from the environment, unquoted with `!!` my_variables <- c("chl", "hyp") plot_corr(mice::nhanes, !!my_variables) # object with variable names must be unquoted with `!!` try(plot_corr(mice::nhanes, my_variables))
Plot the influx and outflux of a multivariate missing data pattern
plot_flux(data, vrb = "all", label = TRUE, caption = TRUE)plot_flux(data, vrb = "all", label = TRUE, caption = TRUE)
data |
An incomplete dataset of class |
vrb |
String, vector, or unquoted expression with variable name(s), default is "all". |
label |
Logical indicating whether variable names should be displayed within the plot (the default) or with colors in the legend. |
caption |
Logical indicating whether the figure caption should be displayed. |
An object of class ggplot2::ggplot.
# plot flux for all columns plot_flux(mice::nhanes) # plot flux for specific columns by supplying a character vector plot_flux(mice::nhanes, c("chl", "hyp")) # plot flux for specific columns by supplying unquoted variable names plot_flux(mice::nhanes, c(chl, hyp)) # plot flux for specific columns by passing an object with variable names # from the environment, unquoted with `!!` my_variables <- c("chl", "hyp") plot_flux(mice::nhanes, !!my_variables) # object with variable names must be unquoted with `!!` try(plot_flux(mice::nhanes, my_variables))# plot flux for all columns plot_flux(mice::nhanes) # plot flux for specific columns by supplying a character vector plot_flux(mice::nhanes, c("chl", "hyp")) # plot flux for specific columns by supplying unquoted variable names plot_flux(mice::nhanes, c(chl, hyp)) # plot flux for specific columns by passing an object with variable names # from the environment, unquoted with `!!` my_variables <- c("chl", "hyp") plot_flux(mice::nhanes, !!my_variables) # object with variable names must be unquoted with `!!` try(plot_flux(mice::nhanes, my_variables))
plot_miss( data, vrb = "all", ordered = FALSE, rotate = FALSE, grid = FALSE, square = FALSE )plot_miss( data, vrb = "all", ordered = FALSE, rotate = FALSE, grid = FALSE, square = FALSE )
data |
An incomplete dataset of class |
vrb |
String, vector, or unquoted expression with variable name(s), default is "all". |
ordered |
Logical indicating whether rows should be ordered according to their pattern. |
rotate |
Logical indicating whether the variable name labels should be rotated 90 degrees. |
grid |
Logical indicating whether borders should be present between tiles. |
square |
Logical indicating whether the plot tiles should be squares, defaults to squares. |
An object of class ggplot2::ggplot.
# plot correlations for all columns plot_miss(mice::nhanes) # plot correlations for specific columns by supplying a character vector plot_miss(mice::nhanes, c("chl", "hyp")) # plot correlations for specific columns by supplying unquoted variable names plot_miss(mice::nhanes, c(chl, hyp)) # plot correlations for specific columns by passing an object with variable names # from the environment, unquoted with `!!` my_variables <- c("chl", "hyp") plot_miss(mice::nhanes, !!my_variables) # object with variable names must be unquoted with `!!` try(plot_miss(mice::nhanes, my_variables)) # plot larger dataset plot_miss(mice::boys) plot_miss(mice::boys, ordered = TRUE)# plot correlations for all columns plot_miss(mice::nhanes) # plot correlations for specific columns by supplying a character vector plot_miss(mice::nhanes, c("chl", "hyp")) # plot correlations for specific columns by supplying unquoted variable names plot_miss(mice::nhanes, c(chl, hyp)) # plot correlations for specific columns by passing an object with variable names # from the environment, unquoted with `!!` my_variables <- c("chl", "hyp") plot_miss(mice::nhanes, !!my_variables) # object with variable names must be unquoted with `!!` try(plot_miss(mice::nhanes, my_variables)) # plot larger dataset plot_miss(mice::boys) plot_miss(mice::boys, ordered = TRUE)
Plot the missing data pattern of an incomplete dataset
plot_pattern( data, vrb = "all", square = TRUE, rotate = FALSE, cluster = NULL, npat = NULL, caption = TRUE )plot_pattern( data, vrb = "all", square = TRUE, rotate = FALSE, cluster = NULL, npat = NULL, caption = TRUE )
data |
An incomplete dataset of class |
vrb |
String, vector, or unquoted expression with variable name(s), default is "all". |
square |
Logical indicating whether the plot tiles should be squares, defaults to squares to mimic |
rotate |
Logical indicating whether the variable name labels should be rotated 90 degrees. |
cluster |
Optional character string specifying which variable should be used for clustering (e.g., for multilevel data). |
npat |
Optional numeric input specifying the maximum number of missing data patterns to be visualized, defaults to all patterns. |
caption |
Logical indicating whether the figure caption should be displayed. |
An object of class ggplot2::ggplot.
# plot missing data pattern for all columns plot_pattern(mice::nhanes) # plot missing data pattern for specific columns by supplying a character vector plot_pattern(mice::nhanes, c("chl", "hyp")) # plot missing data pattern for specific columns by supplying unquoted variable names plot_pattern(mice::nhanes, c(chl, hyp)) # plot missing data pattern for specific columns by passing an object with variable names # from the environment, unquoted with `!!` my_variables <- c("chl", "hyp") plot_pattern(mice::nhanes, !!my_variables) # object with variable names must be unquoted with `!!` try(plot_pattern(mice::nhanes, my_variables)) # plot missing data pattern by cluster plot_pattern(mice::nhanes, cluster = "age")# plot missing data pattern for all columns plot_pattern(mice::nhanes) # plot missing data pattern for specific columns by supplying a character vector plot_pattern(mice::nhanes, c("chl", "hyp")) # plot missing data pattern for specific columns by supplying unquoted variable names plot_pattern(mice::nhanes, c(chl, hyp)) # plot missing data pattern for specific columns by passing an object with variable names # from the environment, unquoted with `!!` my_variables <- c("chl", "hyp") plot_pattern(mice::nhanes, !!my_variables) # object with variable names must be unquoted with `!!` try(plot_pattern(mice::nhanes, my_variables)) # plot missing data pattern by cluster plot_pattern(mice::nhanes, cluster = "age")
Plot the predictor matrix of an imputation model
plot_pred( data, vrb = "all", method = NULL, label = TRUE, square = TRUE, rotate = FALSE )plot_pred( data, vrb = "all", method = NULL, label = TRUE, square = TRUE, rotate = FALSE )
data |
A predictor matrix for |
vrb |
String, vector, or unquoted expression with variable name(s), default is "all". |
method |
Character string or vector with imputation methods. |
label |
Logical indicating whether predictor matrix values should be displayed. |
square |
Logical indicating whether the plot tiles should be squares. |
rotate |
Logical indicating whether the variable name labels should be rotated 90 degrees. |
The predictor matrix in mice::mice determines the role an imputation model predictor takes in the imputation model. The rows correspond to incomplete target variables, and the columns to imputation model predictors.
A value of 1 indicates that the column variable is a predictor to impute the target (row) variable. The value 0 means that it is not used as predictor.
Imputation methods for multilevel data use other codes than 0 and 1:
Methods 2l.bin, 2l.lmer, 2l.norm, 2l.pan, 2lonly.mean, 2lonly.norm and 2lonly.pmm use code -2 to indicate the class variable;
Methods 2l.bin, 2l.lmer, 2l.norm and 2l.pan use code 2 to indicate the random effects;
Method 2l.pan uses codes 3 and 4 to add class means to codes 1 and 2 respectively.
An object of class ggplot2::ggplot.
van Buuren, S. (2018). Flexible imputation of missing data. Chapman and Hall/CRC. stefvanbuuren.name/fimd
# generate a predictor matrix pred <- mice::quickpred(mice::nhanes) # plot predictor matrix for all columns plot_pred(pred) # plot predictor matrix for specific columns by supplying a character vector plot_pred(pred, c("chl", "hyp")) # plot predictor matrix for specific columns by supplying unquoted variable names plot_pred(pred, c(chl, hyp)) # plot predictor matrix for specific columns by passing an object with variable names # from the environment, unquoted with `!!` my_variables <- c("chl", "hyp") plot_pred(pred, !!my_variables) # object with variable names must be unquoted with `!!` try(plot_pred(pred, my_variables)) # plot predictor matrix of mids object imp <- mice::mice(mice::nhanes, print = FALSE) plot_pred(imp)# generate a predictor matrix pred <- mice::quickpred(mice::nhanes) # plot predictor matrix for all columns plot_pred(pred) # plot predictor matrix for specific columns by supplying a character vector plot_pred(pred, c("chl", "hyp")) # plot predictor matrix for specific columns by supplying unquoted variable names plot_pred(pred, c(chl, hyp)) # plot predictor matrix for specific columns by passing an object with variable names # from the environment, unquoted with `!!` my_variables <- c("chl", "hyp") plot_pred(pred, !!my_variables) # object with variable names must be unquoted with `!!` try(plot_pred(pred, my_variables)) # plot predictor matrix of mids object imp <- mice::mice(mice::nhanes, print = FALSE) plot_pred(imp)
Plot the trace lines of the imputation algorithm
plot_trace(data, vrb = "all", trend = FALSE, legend = TRUE)plot_trace(data, vrb = "all", trend = FALSE, legend = TRUE)
data |
An object of class mice::mids. |
vrb |
String, vector, or unquoted expression with variable name(s), default is "all". |
trend |
Logical indicating whether a smoothened trend should be added, default is FALSE. |
legend |
Logical indicating whether the plot legend should be visible, default is TRUE. |
The vrb argument is "quoted" via rlang::enexpr() and evaluated according
to tidy evaluation principles.
In practice, this technical nuance only affects users when passing an object
from the environment (e.g., a vector of variable names) to the vrb argument.
In such cases, the object must be "unquoted" via the !! prefix operator.
An object of class ggplot2::ggplot.
# create [mice::mids] object with [mice::mice()] imp <- mice::mice(mice::nhanes, print = FALSE) # plot trace lines for all imputed columns plot_trace(imp) # plot trace lines for specific columns by supplying a string or character vector plot_trace(imp, "chl") plot_trace(imp, c("chl", "hyp")) # plot trace lines for specific columns by supplying unquoted variable names plot_trace(imp, chl) plot_trace(imp, c(chl, hyp)) # plot trace lines for specific columns by passing an object with variable names # from the environment, unquoted with `!!` my_variables <- c("chl", "hyp") plot_trace(imp, !!my_variables) # object with variable names must be unquoted with `!!` try(plot_trace(imp, my_variables))# create [mice::mids] object with [mice::mice()] imp <- mice::mice(mice::nhanes, print = FALSE) # plot trace lines for all imputed columns plot_trace(imp) # plot trace lines for specific columns by supplying a string or character vector plot_trace(imp, "chl") plot_trace(imp, c("chl", "hyp")) # plot trace lines for specific columns by supplying unquoted variable names plot_trace(imp, chl) plot_trace(imp, c(chl, hyp)) # plot trace lines for specific columns by passing an object with variable names # from the environment, unquoted with `!!` my_variables <- c("chl", "hyp") plot_trace(imp, !!my_variables) # object with variable names must be unquoted with `!!` try(plot_trace(imp, my_variables))
Stripplot of observed and imputed data
stripplot(...)stripplot(...)
... |
Any arguments passed to the function. |
The output of mice::stripplot and a message about the ggmice equivalent.
imp <- mice::mice(mice::nhanes, maxit = 1, printFlag = FALSE) stripplot(imp)imp <- mice::mice(mice::nhanes, maxit = 1, printFlag = FALSE) stripplot(imp)
Scatterplot of observed and imputed data
xyplot(...)xyplot(...)
... |
Any arguments passed to the function. |
The output of mice::xyplot and a message about the ggmice equivalent.
imp <- mice::mice(mice::nhanes, maxit = 1, printFlag = FALSE) xyplot(imp, bmi ~ age)imp <- mice::mice(mice::nhanes, maxit = 1, printFlag = FALSE) xyplot(imp, bmi ~ age)