From 03071262ffaebf5c0de3607f5557ff3e795761de Mon Sep 17 00:00:00 2001 From: hanneoberman Date: Mon, 7 Aug 2023 16:21:42 +0200 Subject: [PATCH 1/8] Increment version number to 0.1.0.9000 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1ce588d1..39077d11 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ggmice Title: Visualizations for 'mice' with 'ggplot2' -Version: 0.1.0 +Version: 0.1.0.9000 Authors@R: c( person("Hanne", "Oberman", email = "h.i.oberman@uu.nl", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-3276-2141")), diff --git a/NEWS.md b/NEWS.md index 82a4b9b0..02008340 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +# ggmice (development version) + # ggmice 0.1.0 ## Breaking changes From beaa379427716790668b0b643c5ec9d8d709ab34 Mon Sep 17 00:00:00 2001 From: hanneoberman Date: Mon, 21 Aug 2023 15:42:29 +0200 Subject: [PATCH 2/8] Add R-universe badge to readme --- README.Rmd | 1 + README.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/README.Rmd b/README.Rmd index 1db17151..ac755552 100644 --- a/README.Rmd +++ b/README.Rmd @@ -18,6 +18,7 @@ knitr::opts_chunk$set( [![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/ggmice)](https://cran.r-project.org/package=ggmice) [![Total CRAN downloads](https://cranlogs.r-pkg.org/badges/grand-total/ggmice)](https://cranlogs.r-pkg.org/badges/grand-total/ggmice) +[![r-universe status badge](https://amices.r-universe.dev/badges/ggmice)](https://amices.r-universe.dev/ggmice) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.6532702.svg)](https://doi.org/10.5281/zenodo.6532702) [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable) diff --git a/README.md b/README.md index 9a6b2925..acbb6602 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ [![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/ggmice)](https://cran.r-project.org/package=ggmice) [![Total CRAN downloads](https://cranlogs.r-pkg.org/badges/grand-total/ggmice)](https://cranlogs.r-pkg.org/badges/grand-total/ggmice) +[![r-universe status +badge](https://amices.r-universe.dev/badges/ggmice)](https://amices.r-universe.dev/ggmice) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.6532702.svg)](https://doi.org/10.5281/zenodo.6532702) [![Lifecycle: From 2bce8108458e68afa5af854771de1a03cb63e350 Mon Sep 17 00:00:00 2001 From: hanneoberman Date: Thu, 7 Sep 2023 17:00:41 +0200 Subject: [PATCH 3/8] Phrasing 'on top of axis' in vignette --- vignettes/ggmice.Rmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vignettes/ggmice.Rmd b/vignettes/ggmice.Rmd index 10a1abc9..9331df98 100644 --- a/vignettes/ggmice.Rmd +++ b/vignettes/ggmice.Rmd @@ -90,7 +90,7 @@ The `mapping` argument in `ggmice()` cannot be empty. An `x` or `y` mapping (or ## Incomplete data -If the object supplied to the `data` argument in `ggmice()` is a `data.frame`, the visualization will contain observed data in blue and missing data in red. Since missing data points are by definition unobserved, the values themselves cannot be plotted. What we *can* plot are sets of variable pairs. Any missing values on one variable can be displayed on top of the axis of the other. This provides a visual cue that the missing data is distinct from the observed values, but still displays the observed value of the other variable. +If the object supplied to the `data` argument in `ggmice()` is a `data.frame`, the visualization will contain observed data in blue and missing data in red. Since missing data points are by definition unobserved, the values themselves cannot be plotted. What we *can* plot are sets of variable pairs. Any missing values in one variable can be displayed on the axis of the other. This provides a visual cue that the missing data is distinct from the observed values, but still displays the observed value of the other variable. For example, the variable `age` is completely observed, while there are some missing entries for the height variable `hgt`. We can create a scatter plot of these two variables with: @@ -99,7 +99,7 @@ ggmice(dat, aes(age, hgt)) + geom_point() ``` -The `age` of cases with missing `hgt` are plotted on top of the horizontal axis. This is in contrast to a regular `ggplot()` call with the same arguments, which would leave out all cases with missing `hgt`. So, with `ggmice()` we loose less information, and may even gain valuable insight into the missingness in the data. +The `age` of cases with missing `hgt` are plotted on the horizontal axis. This is in contrast to a regular `ggplot()` call with the same arguments, which would leave out all cases with missing `hgt`. So, with `ggmice()` we loose less information, and may even gain valuable insight into the missingness in the data. Another example of `ggmice()` in action on incomplete data is when one of the variables is categorical. The incomplete continuous variable `hgt` is plotted against the incomplete categorical variable `reg` with: @@ -108,7 +108,7 @@ ggmice(dat, aes(reg, hgt)) + geom_point() ``` -Again, missing values are plotted on top of the axes. Cases with observed `hgt` and missing `reg` are plotted on top of the vertical axis. Cases with observed `reg` and missing `hgt` are plotted on top of the horizontal axis. There are no cases were neither is observed, but otherwise these would be plotted on the intersection of the two axes. +Again, missing values are plotted on the axes. Cases with observed `hgt` and missing `reg` are plotted on the vertical axis. Cases with observed `reg` and missing `hgt` are plotted on the horizontal axis. There are no cases were neither is observed, but otherwise these would be plotted on the intersection of the two axes. The 'grammar of graphics' makes it easy to adjust the plots programmatically. For example, we could be interested in the differences in growth data between the city and other regions. Add facets based on a clustering variable with: From d2768f2d42030e16396e129bda2164853a39d38e Mon Sep 17 00:00:00 2001 From: hanneoberman Date: Wed, 4 Oct 2023 10:21:27 +0200 Subject: [PATCH 4/8] Fix #125 --- R/plot_pred.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/R/plot_pred.R b/R/plot_pred.R index 2cc425c7..f1484a87 100644 --- a/R/plot_pred.R +++ b/R/plot_pred.R @@ -50,13 +50,13 @@ plot_pred <- ind = matrix(data, nrow = p * p, byrow = TRUE) ) %>% dplyr::mutate(clr = factor( .data$ind, - levels = c(-2, 0, 1, 2, 3), + levels = c(-3, -2, 0, 1, 2), labels = c( + "inclusion-restriction variable", "cluster variable", "not used", "predictor", - "random effect", - "inclusion-restriction variable" + "random effect" ), ordered = TRUE )) @@ -78,11 +78,11 @@ plot_pred <- ) + ggplot2::scale_fill_manual( values = c( + "inclusion-restriction variable" = "orangered", "cluster variable" = "lightyellow", "not used" = "grey90", "predictor" = "palegreen3", - "random effect" = "deepskyblue", - "inclusion-restriction variable" = "orangered" + "random effect" = "deepskyblue" ) ) + ggplot2::labs( From a0549d4ca6dc625ccd4ce05970c3bd5d1c8fc7b8 Mon Sep 17 00:00:00 2001 From: hanneoberman Date: Mon, 6 Nov 2023 17:16:47 +0100 Subject: [PATCH 5/8] Add example imputed data to `ggmice()` docs --- R/ggmice.R | 2 ++ man/ggmice.Rd | 2 ++ 2 files changed, 4 insertions(+) diff --git a/R/ggmice.R b/R/ggmice.R index 70b9b6a0..e03306c6 100644 --- a/R/ggmice.R +++ b/R/ggmice.R @@ -8,6 +8,8 @@ #' @examples #' 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() #' @seealso See the `ggmice` vignette to use the `ggmice()` function on #' [incomplete data](https://amices.org/ggmice/articles/ggmice.html#the-ggmice-function) #' or [imputed data](https://amices.org/ggmice/articles/ggmice.html#the-ggmice-function-1). diff --git a/man/ggmice.Rd b/man/ggmice.Rd index 983e27ed..894b059c 100644 --- a/man/ggmice.Rd +++ b/man/ggmice.Rd @@ -20,6 +20,8 @@ Plot incomplete or imputed data \examples{ 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() } \seealso{ See the \code{ggmice} vignette to use the \code{ggmice()} function on From 0047e480e6247c800dfad1de2b96e2568f66a5b0 Mon Sep 17 00:00:00 2001 From: hanneoberman Date: Thu, 9 Nov 2023 15:43:15 +0100 Subject: [PATCH 6/8] whitespace linting and code comments --- R/utils.R | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/R/utils.R b/R/utils.R index 67fcf484..2cb42595 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,6 +1,6 @@ # Functions for internal use -# util functions +# Shorthand 'not in' for code readability `%nin%` <- Negate(`%in%`) #' Pipe operator @@ -19,11 +19,6 @@ #' @return The result of calling `rhs(lhs)`. NULL -# suppress undefined global functions or variables note -utils::globalVariables(c(".id", ".imp", ".where", ".id", "where", "name", "value")) - -# Alias a function with `foo <- function(...) pkgB::blah(...)` - #' Utils function to validate data argument inputs #' #' @param data The input supplied to the 'data' argument. @@ -104,3 +99,6 @@ verify_data <- function(data, } } } + +# suppress undefined global functions or variables note +utils::globalVariables(c(".id", ".imp", ".where", ".id", "where", "name", "value")) From 7dd53cb9bcc86e5da58f44c3a432f1fd79a04ed0 Mon Sep 17 00:00:00 2001 From: hanneoberman Date: Thu, 9 Nov 2023 16:02:39 +0100 Subject: [PATCH 7/8] Add news dev version --- NEWS.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 02008340..ef10f9d5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,15 @@ # ggmice (development version) +## Bug fixes + +* Correct labeling of 'exclusion-restriction' variables in `plot_pred()` (#128) + +## Minor changes + +* Miscellaneous documentation and vignette updates (#128) + +--- + # ggmice 0.1.0 ## Breaking changes @@ -27,7 +37,7 @@ * Input validation for `data` argument `plot_*` functions (#85) * Input validation for `vrb` argument `plot_*` functions (#80) * Input validation for `mapping` argument `ggmice()` (#34, #90) -* Vignette updates (PRs #31, #35, #38) and other documentation (#45, #51) +* Vignette updates (#31, #35, #38) and other documentation (#45, #51) * The `plot_pattern()` function creates missing data pattern plot with more informative labels (#59, #111) --- From 6b5863c2b73777cc25bf1dabe9a6d02f984325c1 Mon Sep 17 00:00:00 2001 From: hanneoberman Date: Thu, 21 Dec 2023 13:37:38 +0100 Subject: [PATCH 8/8] Extend documentation output `ggmice()` --- R/ggmice.R | 12 +++++++++--- man/ggmice.Rd | 9 ++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/R/ggmice.R b/R/ggmice.R index e03306c6..3ab1862e 100644 --- a/R/ggmice.R +++ b/R/ggmice.R @@ -3,7 +3,13 @@ #' @param data An incomplete dataset (of class `data.frame`), or an object of class [`mice::mids`]. #' @param mapping A list of aesthetic mappings created with [ggplot2::aes()]. #' -#' @return An object of class [`ggplot2::ggplot`]. +#' @return An object of class [`ggplot2::ggplot`]. The [`ggmice::ggmice`] function returns output +#' equivalent to [`ggplot2::ggplot`] output, with a few important exceptions: +#' +#' - The theme is set to [`ggmice::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). #' #' @examples #' dat <- mice::nhanes @@ -101,8 +107,8 @@ ggmice <- function(data = NULL, .imp = 0, .id = rownames(data$data), data$data - )[!miss_xy, ], - data.frame(.where = "imputed", mice::complete(data, action = "long"))[where_xy, ] + )[!miss_xy,], + data.frame(.where = "imputed", mice::complete(data, action = "long"))[where_xy,] ), .where = factor( .where, diff --git a/man/ggmice.Rd b/man/ggmice.Rd index 894b059c..523e8005 100644 --- a/man/ggmice.Rd +++ b/man/ggmice.Rd @@ -12,7 +12,14 @@ ggmice(data = NULL, mapping = ggplot2::aes()) \item{mapping}{A list of aesthetic mappings created with \code{\link[ggplot2:aes]{ggplot2::aes()}}.} } \value{ -An object of class \code{\link[ggplot2:ggplot]{ggplot2::ggplot}}. +An object of class \code{\link[ggplot2:ggplot]{ggplot2::ggplot}}. The \code{\link{ggmice}} function returns output +equivalent to \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} output, with a few important exceptions: +\itemize{ +\item The theme is set to \code{\link{theme_mice}}. +\item The color scale is set to the \code{\link[mice:mdc]{mice::mdc}} colors. +\item The \code{colour} aesthetic is set to \code{.where}, an internally defined variable which distinguishes +observed data from missing data or imputed data (for incomplete and imputed data, respectively). +} } \description{ Plot incomplete or imputed data