From 7d4142db1f0c59e7756c9147a6b722ca3fd05b47 Mon Sep 17 00:00:00 2001 From: Andrei Martins <92amartins@gmail.com> Date: Thu, 25 Apr 2024 13:27:17 -0300 Subject: [PATCH] fix: ggparcoord anyClass ordering with missing values in data --- NEWS.md | 2 ++ R/ggparcoord.R | 1 + tests/testthat/test-ggparcoord.R | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/NEWS.md b/NEWS.md index 12445271a..dc59905f6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # GGally (development version) +* Fix anyClass ordering in ggparcoord when data has missing values (#500) + # GGally 2.2.1 * Fix compatibility with ggplot2 3.5.0 (@teunbrand, #481) diff --git a/R/ggparcoord.R b/R/ggparcoord.R index ad6cf2ad2..fde5d737a 100644 --- a/R/ggparcoord.R +++ b/R/ggparcoord.R @@ -396,6 +396,7 @@ ggparcoord <- function( } data <- data[dataCompleteCases, ] + saveData2 <- saveData2[dataCompleteCases, ] } else if (tolower(missing) %in% c("mean", "median", "min10", "random")) { missingFns <- list( mean = function(x) { diff --git a/tests/testthat/test-ggparcoord.R b/tests/testthat/test-ggparcoord.R index 2cf67f8b1..c6d6e1e3a 100644 --- a/tests/testthat/test-ggparcoord.R +++ b/tests/testthat/test-ggparcoord.R @@ -227,6 +227,17 @@ test_that("order", { } }) +test_that("missing and order(anyClass)", { + ds2 <- diamonds.samp + ds2[3, 1] <- NA + missing_options <- c("exclude", "mean", "median", "min10", "random") + + for (missing in missing_options) { + p <- ggparcoord(data = ds2, columns = c(1, 5:10), groupColumn = 2, missing = missing, order = "anyClass") + } + expect_true(TRUE) +}) + test_that("basic", { # no color supplied p <- ggparcoord(data = diamonds.samp, columns = c(1, 5:10))