From ce373662f9849328f57abc2a7c392f9c232b9d93 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 27 Sep 2024 15:05:35 +0200 Subject: [PATCH 01/11] Issue plotting lme4 random effects from `model_parameters` Fixes #365 --- DESCRIPTION | 2 +- NEWS.md | 3 + R/plot.parameters_model.R | 159 ++++++++++++++++++++++++++++++++------ 3 files changed, 139 insertions(+), 25 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 30fb12014..ece871c83 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: see Title: Model Visualisation Toolbox for 'easystats' and 'ggplot2' -Version: 0.9.0.2 +Version: 0.9.0.3 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NEWS.md b/NEWS.md index d0c299923..0246faa94 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,9 @@ - `plot()` for `p_function()` now checks the values of the `size_length` argument, to give an informative error message when the input is not valid. +- `plot()` for `model_parameters()` now also plots group-levels of random effects + (i.e. for mixed models, when `model_parameters(x, ..., group_level = TRUE)`). + # see 0.9.0 ## Changes diff --git a/R/plot.parameters_model.R b/R/plot.parameters_model.R index 6206c4066..884a8110a 100644 --- a/R/plot.parameters_model.R +++ b/R/plot.parameters_model.R @@ -53,6 +53,14 @@ plot.see_parameters_model <- function(x, # retrieve settings ---------------- model_attributes <- attributes(x)[!names(attributes(x)) %in% c("names", "row.names", "class")] + # user wants to plot random effects (group levels)? + if (isFALSE(model_attributes$ignore_group) && isTRUE(model_attributes$mixed_model)) { + if (missing(show_intercept)) { + show_intercept <- TRUE + } + return(.group_level_plot(x, size_point, size_text, sort, n_columns, show_intercept, show_labels, ...)) + } + # show intercept for intercept-only models if (insight::is_model(x) && insight::is_nullmodel(x)) { show_intercept <- TRUE @@ -461,21 +469,21 @@ plot.see_parameters_model <- function(x, # values we can use as breaks and labels for the scale... if (exponentiated_coefs && log_scale) { - range <- 2^(-24:16) - x_low <- which.min(min_ci > range) - 1 - x_high <- which.max(max_ci < range) + axis_range <- 2^(-24:16) + x_low <- which.min(min_ci > axis_range) - 1 + x_high <- which.max(max_ci < axis_range) if (add_values) { # add some space to the right panel for text new_range <- pretty(2 * max_ci) - x_high <- which.max(max(new_range) < range) + x_high <- which.max(max(new_range) < axis_range) } p <- p + scale_x_continuous( trans = "log", - breaks = range[x_low:x_high], - limits = c(range[x_low], range[x_high]), - labels = sprintf("%g", range[x_low:x_high]) + breaks = axis_range[x_low:x_high], + limits = c(axis_range[x_low], axis_range[x_high]), + labels = sprintf("%g", axis_range[x_low:x_high]) ) } @@ -526,32 +534,135 @@ plot.see_parameters_model <- function(x, if (isTRUE(is_meta)) { measure <- .meta_measure(meta_measure) - p + labs( + p + ggplot2::labs( y = "", x = measure, colour = "CI" ) + } else if (isTRUE(axis_title_in_facet)) { + p + ggplot2::labs( + y = parameter_label, + x = NULL, + colour = "CI" + ) } else { - if (isTRUE(axis_title_in_facet)) { - p + labs( - y = parameter_label, - x = NULL, - colour = "CI" - ) - } else { - p + labs( - y = parameter_label, - x = ifelse(is.null(coefficient_name), - ifelse(exponentiated_coefs, "Exp(Estimate)", "Estimate"), # nolint - coefficient_name - ), - colour = "CI" - ) - } + p + ggplot2::labs( + y = parameter_label, + x = ifelse(is.null(coefficient_name), + ifelse(exponentiated_coefs, "Exp(Estimate)", "Estimate"), # nolint + coefficient_name + ), + colour = "CI" + ) } } +.group_level_plot <- function(x, size_point, size_text, sort, n_columns, show_intercept, show_labels, ...) { + # filter random effects + x <- x[x$Effects == "random", ] + # remove intercept? + if (isFALSE(show_intercept) && length(.is_intercept(x$Parameter)) > 0L) { + x <- x[!.is_intercept(x$Parameter), ] + } + # prepare group variable + x$Group <- paste(x$Group, x$Parameter, sep = ": ") + + # define columns + if (is.null(n_columns)) { + n_columns <- 1 + } + + # define text size + if (is.null(size_text) || is.na(size_text)) { + size_text <- 4 + } + + # for now, we fix the NULL to 0. Maybe we could exp() random parameters + # for logistic regression and similar models, but currently only link-scale + y_intercept <- 0 + + # plot setup for regular model parameters + x$colored <- factor(x$Coefficient < y_intercept, levels = c(FALSE, TRUE)) + if (all(x$colored == "TRUE")) { + color_scale <- scale_color_material(reverse = TRUE) + fill_scale <- scale_fill_material(reverse = TRUE) + } else { + color_scale <- scale_color_material() + fill_scale <- scale_fill_material() + } + + # create text string for estimate and CI + x$Estimate_CI <- sprintf( + "%.2f %s", + x$Coefficient, + insight::format_ci(x$CI_low, x$CI_high, ci = NULL, digits = 2, zap_small = TRUE) + ) + + # handle sorting + if (isTRUE(sort) || (!is.null(sort) && sort == "ascending")) { + x$Level <- factor(x$Level, levels = rev(unique(x$Level)[order(x$Coefficient)])) + } else if (!is.null(sort) && sort == "descending") { + x$Level <- factor(x$Level, levels = unique(x$Level)[order(x$Coefficient)]) + } else { + # sort coefficients as they appear in the classical summary output by default + x$Level <- factor(x$Level, levels = rev(unique(x$Level))) + } + + # find min/max range based on CI + min_ci <- min(x$CI_low, na.rm = TRUE) + max_ci <- max(x$CI_high, na.rm = TRUE) + + p <- ggplot2::ggplot( + x, + ggplot2::aes( + x = .data$Coefficient, + y = .data$Level, + xmin = .data$CI_low, + xmax = .data$CI_high, + colour = .data$colored, + fill = .data$colored + ) + ) + + ggplot2::geom_vline( + ggplot2::aes(xintercept = y_intercept), + linetype = "dotted", + colour = "black" + ) + + theme_modern(legend.position = "none") + + color_scale + + fill_scale + + ggplot2::geom_errorbarh( + height = 0, + linewidth = size_point + ) + + ggplot2::geom_point( + size = 4 * size_point, + colour = "white", + shape = 21 + ) + + ggplot2::facet_wrap(~Group, ncol = n_columns) + + # add coefficients and CIs? + if (isTRUE(show_labels)) { + # add some space to the right panel for text + space_factor <- (n_columns^(size_text / 1.2)) * sqrt(ceiling(diff(c(min_ci, max_ci))) / 5) + new_range <- pretty(c(min_ci, max_ci + space_factor)) + + # expand scale range and add numbers to the right border + if (!any(is.infinite(new_range)) && !anyNA(new_range)) { + p <- p + + ggplot2::geom_text( + mapping = ggplot2::aes(label = .data$Estimate_CI, x = Inf), + colour = "black", hjust = "inward", size = size_text + ) + + ggplot2::xlim(c(min(new_range), max(new_range))) + } + } + + p +} + .funnel_plot <- function(x, size_point = 3, meta_measure = NULL) { max_y <- max(pretty(max(x$SE) * 105)) / 100 From 1d3e32ea7f626dc84e66fc3bb8ac3ae3c514d622 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 27 Sep 2024 16:32:24 +0200 Subject: [PATCH 02/11] add tests --- .../plot-model-parameters-1.svg | 93 ++++++ .../plot-model-parameters-random-0.svg | 93 ++++++ .../plot-model-parameters-random-1.svg | 256 ++++++++++++++++ .../plot-model-parameters-random-2.svg | 290 ++++++++++++++++++ .../plot-model-parameters-random-3.svg | 290 ++++++++++++++++++ .../plot-model-parameters-random-4.svg | 290 ++++++++++++++++++ .../plot-model-parameters-random-5.svg | 281 +++++++++++++++++ .../plot-model-parameters-random-6.svg | 162 ++++++++++ tests/testthat/test-plot.parameters_model.R | 58 +++- 9 files changed, 1812 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-1.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-0.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-1.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-2.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-3.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-4.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-5.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-6.svg diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-1.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-1.svg new file mode 100644 index 000000000..ba2c1abe1 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-1.svg @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Random Effects + + + + + + + + + +Fixed Effects + + + +0 +10 +20 +30 + +0 +5 +10 + +Days + +SD (Observations) +SD (Days) +Coefficient +plot.model_parameters_1 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-0.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-0.svg new file mode 100644 index 000000000..c9efd6bd8 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-0.svg @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Random Effects + + + + + + + + + +Fixed Effects + + + +0 +10 +20 +30 + +0 +5 +10 + +Days + +SD (Observations) +SD (Days) +Coefficient +plot.model_parameters_random_0 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-1.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-1.svg new file mode 100644 index 000000000..aad093030 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-1.svg @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Subject: Days + + + + + + + + + +Subject: (Intercept) + + + +-60 +-30 +0 +30 +60 + +372 +371 +370 +369 +352 +351 +350 +349 +337 +335 +334 +333 +332 +331 +330 +310 +309 +308 + +372 +371 +370 +369 +352 +351 +350 +349 +337 +335 +334 +333 +332 +331 +330 +310 +309 +308 +Coefficient +Level +plot.model_parameters_random_1 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-2.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-2.svg new file mode 100644 index 000000000..7b60e0279 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-2.svg @@ -0,0 +1,290 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.26 [-21.40, 25.92] +-40.40 [-64.06, -16.74] +-38.96 [-62.62, -15.30] +23.69 [0.03, 47.35] +22.26 [-1.40, 45.92] +9.04 [-14.62, 32.70] +16.84 [-6.82, 40.50] +-7.23 [-30.89, 16.43] +-0.33 [-23.99, 23.32] +34.89 [11.23, 58.55] +-25.21 [-48.87, -1.55] +-13.07 [-36.73, 10.59] +4.58 [-19.08, 28.24] +20.86 [-2.79, 44.52] +3.28 [-20.38, 26.93] +-25.61 [-49.27, -1.95] +0.81 [-22.85, 24.47] +12.31 [-11.34, 35.97] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +9.20 [4.68, 13.72] +-8.62 [-13.14, -4.10] +-5.45 [-9.97, -0.93] +-4.81 [-9.33, -0.30] +-3.07 [-7.59, 1.45] +-0.27 [-4.79, 4.25] +-0.22 [-4.74, 4.29] +1.07 [-3.44, 5.59] +-10.75 [-15.27, -6.23] +8.63 [4.11, 13.15] +1.17 [-3.34, 5.69] +6.61 [2.10, 11.13] +-3.02 [-7.53, 1.50] +3.54 [-0.98, 8.05] +0.87 [-3.65, 5.39] +4.82 [0.31, 9.34] +-0.99 [-5.51, 3.53] +1.28 [-3.23, 5.80] + + + + + + + + + +Subject: Days + + + + + + + + + +Subject: (Intercept) + + + +-50 +0 +50 + +372 +371 +370 +369 +352 +351 +350 +349 +337 +335 +334 +333 +332 +331 +330 +310 +309 +308 + +372 +371 +370 +369 +352 +351 +350 +349 +337 +335 +334 +333 +332 +331 +330 +310 +309 +308 +Coefficient +Level +plot.model_parameters_random_2 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-3.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-3.svg new file mode 100644 index 000000000..1cccf6187 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-3.svg @@ -0,0 +1,290 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.26 [-21.40, 25.92] +-40.40 [-64.06, -16.74] +-38.96 [-62.62, -15.30] +23.69 [0.03, 47.35] +22.26 [-1.40, 45.92] +9.04 [-14.62, 32.70] +16.84 [-6.82, 40.50] +-7.23 [-30.89, 16.43] +-0.33 [-23.99, 23.32] +34.89 [11.23, 58.55] +-25.21 [-48.87, -1.55] +-13.07 [-36.73, 10.59] +4.58 [-19.08, 28.24] +20.86 [-2.79, 44.52] +3.28 [-20.38, 26.93] +-25.61 [-49.27, -1.95] +0.81 [-22.85, 24.47] +12.31 [-11.34, 35.97] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +9.20 [4.68, 13.72] +-8.62 [-13.14, -4.10] +-5.45 [-9.97, -0.93] +-4.81 [-9.33, -0.30] +-3.07 [-7.59, 1.45] +-0.27 [-4.79, 4.25] +-0.22 [-4.74, 4.29] +1.07 [-3.44, 5.59] +-10.75 [-15.27, -6.23] +8.63 [4.11, 13.15] +1.17 [-3.34, 5.69] +6.61 [2.10, 11.13] +-3.02 [-7.53, 1.50] +3.54 [-0.98, 8.05] +0.87 [-3.65, 5.39] +4.82 [0.31, 9.34] +-0.99 [-5.51, 3.53] +1.28 [-3.23, 5.80] + + + + + + + + + +Subject: Days + + + + + + + + + +Subject: (Intercept) + + + +-50 +0 +50 + +372 +371 +370 +369 +352 +351 +350 +349 +337 +335 +334 +333 +332 +331 +330 +310 +309 +308 + +372 +371 +370 +369 +352 +351 +350 +349 +337 +335 +334 +333 +332 +331 +330 +310 +309 +308 +Coefficient +Level +plot.model_parameters_random_3 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-4.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-4.svg new file mode 100644 index 000000000..87fa94a0e --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-4.svg @@ -0,0 +1,290 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.26 [-21.40, 25.92] +-40.40 [-64.06, -16.74] +-38.96 [-62.62, -15.30] +23.69 [0.03, 47.35] +22.26 [-1.40, 45.92] +9.04 [-14.62, 32.70] +16.84 [-6.82, 40.50] +-7.23 [-30.89, 16.43] +-0.33 [-23.99, 23.32] +34.89 [11.23, 58.55] +-25.21 [-48.87, -1.55] +-13.07 [-36.73, 10.59] +4.58 [-19.08, 28.24] +20.86 [-2.79, 44.52] +3.28 [-20.38, 26.93] +-25.61 [-49.27, -1.95] +0.81 [-22.85, 24.47] +12.31 [-11.34, 35.97] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +9.20 [4.68, 13.72] +-8.62 [-13.14, -4.10] +-5.45 [-9.97, -0.93] +-4.81 [-9.33, -0.30] +-3.07 [-7.59, 1.45] +-0.27 [-4.79, 4.25] +-0.22 [-4.74, 4.29] +1.07 [-3.44, 5.59] +-10.75 [-15.27, -6.23] +8.63 [4.11, 13.15] +1.17 [-3.34, 5.69] +6.61 [2.10, 11.13] +-3.02 [-7.53, 1.50] +3.54 [-0.98, 8.05] +0.87 [-3.65, 5.39] +4.82 [0.31, 9.34] +-0.99 [-5.51, 3.53] +1.28 [-3.23, 5.80] + + + + + + + + + +Subject: Days + + + + + + + + + +Subject: (Intercept) + + + +-50 +0 +50 + +337 +330 +331 +352 +333 +372 +332 +351 +369 +308 +371 +335 +334 +350 +349 +370 +310 +309 + +337 +330 +331 +352 +333 +372 +332 +351 +369 +308 +371 +335 +334 +350 +349 +370 +310 +309 +Coefficient +Level +plot.model_parameters_random_4 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-5.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-5.svg new file mode 100644 index 000000000..e69c31930 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-5.svg @@ -0,0 +1,281 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.26 [-21.40, 25.92] +-40.40 [-64.06, -16.74] +-38.96 [-62.62, -15.30] +23.69 [0.03, 47.35] +22.26 [-1.40, 45.92] +9.04 [-14.62, 32.70] +16.84 [-6.82, 40.50] +-7.23 [-30.89, 16.43] +-0.33 [-23.99, 23.32] +34.89 [11.23, 58.55] +-25.21 [-48.87, -1.55] +-13.07 [-36.73, 10.59] +4.58 [-19.08, 28.24] +20.86 [-2.79, 44.52] +3.28 [-20.38, 26.93] +-25.61 [-49.27, -1.95] +0.81 [-22.85, 24.47] +12.31 [-11.34, 35.97] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +9.20 [4.68, 13.72] +-8.62 [-13.14, -4.10] +-5.45 [-9.97, -0.93] +-4.81 [-9.33, -0.30] +-3.07 [-7.59, 1.45] +-0.27 [-4.79, 4.25] +-0.22 [-4.74, 4.29] +1.07 [-3.44, 5.59] +-10.75 [-15.27, -6.23] +8.63 [4.11, 13.15] +1.17 [-3.34, 5.69] +6.61 [2.10, 11.13] +-3.02 [-7.53, 1.50] +3.54 [-0.98, 8.05] +0.87 [-3.65, 5.39] +4.82 [0.31, 9.34] +-0.99 [-5.51, 3.53] +1.28 [-3.23, 5.80] + + + + + + + + + +Subject: (Intercept) + + + + + + + + + +Subject: Days + + + +-100 +-50 +0 +50 +100 +150 + +-100 +-50 +0 +50 +100 +150 + +337 +330 +331 +352 +333 +372 +332 +351 +369 +308 +371 +335 +334 +350 +349 +370 +310 +309 +Coefficient +Level +plot.model_parameters_random_5 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-6.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-6.svg new file mode 100644 index 000000000..be78806e0 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-6.svg @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +9.20 [4.68, 13.72] +-8.62 [-13.14, -4.10] +-5.45 [-9.97, -0.93] +-4.81 [-9.33, -0.30] +-3.07 [-7.59, 1.45] +-0.27 [-4.79, 4.25] +-0.22 [-4.74, 4.29] +1.07 [-3.44, 5.59] +-10.75 [-15.27, -6.23] +8.63 [4.11, 13.15] +1.17 [-3.34, 5.69] +6.61 [2.10, 11.13] +-3.02 [-7.53, 1.50] +3.54 [-0.98, 8.05] +0.87 [-3.65, 5.39] +4.82 [0.31, 9.34] +-0.99 [-5.51, 3.53] +1.28 [-3.23, 5.80] + + + + + + + + + +Subject: Days + + + +-20 +-10 +0 +10 +20 + +308 +337 +350 +370 +352 +372 +349 +334 +369 +333 +332 +371 +351 +331 +330 +310 +309 +335 +Coefficient +Level +plot.model_parameters_random_6 + + diff --git a/tests/testthat/test-plot.parameters_model.R b/tests/testthat/test-plot.parameters_model.R index 7a52d8b6f..56a7aceee 100644 --- a/tests/testthat/test-plot.parameters_model.R +++ b/tests/testthat/test-plot.parameters_model.R @@ -1,6 +1,62 @@ test_that("`plot.see_parameters_model()` works", { m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars) result <- parameters::model_parameters(m) - expect_s3_class(plot(result), "gg") + + skip_if_not_installed("vdiffr") + vdiffr::expect_doppelganger( + title = "plot.model_parameters_1", + fig = plot(out) + ) +}) + +test_that("`plot.see_parameters_model()` random parameters works", { + skip_if_not_installed("vdiffr") + skip_if_not_installed("lme4") + skip_if_not_installed("parameters") + + data(sleepstudy, package = "lme4") + s_mod <- lme4::lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy) + + out <- parameters::model_parameters(s_mod) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_0", + fig = plot(out) + ) + + out <- parameters::model_parameters(s_mod, group_level = TRUE) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_1", + fig = plot(out) + ) + + out <- parameters::model_parameters(s_mod, group_level = TRUE) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_2", + fig = plot(out, show_labels = TRUE) + ) + + out <- parameters::model_parameters(s_mod, group_level = TRUE) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_3", + fig = plot(out, show_labels = TRUE, size_text = 5) + ) + + out <- parameters::model_parameters(s_mod, group_level = TRUE) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_4", + fig = plot(out, sort = "ascending", show_labels = TRUE) + ) + + out <- parameters::model_parameters(s_mod, group_level = TRUE) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_5", + fig = plot(out, sort = "ascending", show_labels = TRUE, n_columns = 2) + ) + + out <- parameters::model_parameters(s_mod, group_level = TRUE) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_6", + fig = plot(out, sort = "ascending", show_labels = TRUE, show_intercept = FALSE) + ) }) From 14c903c963f7bc96ad292f6d79650ea06746b6a3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 27 Sep 2024 16:38:59 +0200 Subject: [PATCH 03/11] update plots --- DESCRIPTION | 1 + .../plot-check-dag-all-adjusted.svg | 18 +++++++++--------- .../plot.check_dag/plot-check-dag-all.svg | 18 +++++++++--------- .../plot.check_dag/plot-check-dag-direct1.svg | 18 +++++++++--------- .../plot.check_dag/plot-check-dag-direct2.svg | 18 +++++++++--------- .../plot.check_dag/plot-check-dag-direct3.svg | 18 +++++++++--------- .../plot.check_dag/plot-check-dag-direct4.svg | 18 +++++++++--------- .../plot-check-dag-multiple-adjustments.svg | 18 +++++++++--------- .../plot.check_dag/plot-check-dag-total1.svg | 18 +++++++++--------- .../plot.check_dag/plot-check-dag-total2.svg | 18 +++++++++--------- .../plot.check_dag/plot-check-dag-total3.svg | 18 +++++++++--------- .../plot.check_dag/plot-check-dag-total4.svg | 18 +++++++++--------- tests/testthat/test-plot.parameters_model.R | 2 +- 13 files changed, 101 insertions(+), 100 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ece871c83..78c8367b1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -121,3 +121,4 @@ Config/testthat/edition: 3 Config/testthat/parallel: true Config/Needs/website: easystats/easystatstemplate Config/rcmdcheck/ignore-inconsequential-notes: true +Remotes: easystats/performance diff --git a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-all-adjusted.svg b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-all-adjusted.svg index 95822a2db..d563dc99a 100644 --- a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-all-adjusted.svg +++ b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-all-adjusted.svg @@ -38,6 +38,15 @@ + + + + + + + + + @@ -69,15 +78,6 @@ Current model - - - - - - - - - diff --git a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-all.svg b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-all.svg index 8b86196b3..9fc49c707 100644 --- a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-all.svg +++ b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-all.svg @@ -38,6 +38,15 @@ + + + + + + + + + @@ -69,15 +78,6 @@ Current model - - - - - - - - - diff --git a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct1.svg b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct1.svg index e76ef0ca3..3bd5ada8c 100644 --- a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct1.svg +++ b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct1.svg @@ -38,6 +38,15 @@ + + + + + + + + + @@ -72,15 +81,6 @@ Current model - - - - - - - - - diff --git a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct2.svg b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct2.svg index da4d27376..9f67b8091 100644 --- a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct2.svg +++ b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct2.svg @@ -38,6 +38,15 @@ + + + + + + + + + @@ -80,15 +89,6 @@ unadjusted Current model - - - - - - - - - diff --git a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct3.svg b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct3.svg index f4abadf97..7c0225943 100644 --- a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct3.svg +++ b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct3.svg @@ -38,6 +38,15 @@ + + + + + + + + + @@ -80,15 +89,6 @@ unadjusted Current model - - - - - - - - - diff --git a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct4.svg b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct4.svg index 72f80e6af..309d2b0eb 100644 --- a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct4.svg +++ b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct4.svg @@ -38,6 +38,15 @@ + + + + + + + + + @@ -72,15 +81,6 @@ Current model - - - - - - - - - diff --git a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-multiple-adjustments.svg b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-multiple-adjustments.svg index 90c2c7d2e..edf9b6f1f 100644 --- a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-multiple-adjustments.svg +++ b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-multiple-adjustments.svg @@ -38,6 +38,15 @@ + + + + + + + + + @@ -88,15 +97,6 @@ Current model - - - - - - - - - diff --git a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total1.svg b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total1.svg index 428c5a28f..0f5d9db17 100644 --- a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total1.svg +++ b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total1.svg @@ -38,6 +38,15 @@ + + + + + + + + + @@ -72,15 +81,6 @@ Current model - - - - - - - - - diff --git a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total2.svg b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total2.svg index 58447c6e8..4f6ee0763 100644 --- a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total2.svg +++ b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total2.svg @@ -38,6 +38,15 @@ + + + + + + + + + @@ -72,15 +81,6 @@ Current model - - - - - - - - - diff --git a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total3.svg b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total3.svg index ce20d9a44..c6c7f251c 100644 --- a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total3.svg +++ b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total3.svg @@ -38,6 +38,15 @@ + + + + + + + + + @@ -80,15 +89,6 @@ unadjusted Current model - - - - - - - - - diff --git a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total4.svg b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total4.svg index e5ddeaada..77504bc48 100644 --- a/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total4.svg +++ b/tests/testthat/_snaps/plot.check_dag/plot-check-dag-total4.svg @@ -38,6 +38,15 @@ + + + + + + + + + @@ -72,15 +81,6 @@ Current model - - - - - - - - - diff --git a/tests/testthat/test-plot.parameters_model.R b/tests/testthat/test-plot.parameters_model.R index 56a7aceee..fa3321224 100644 --- a/tests/testthat/test-plot.parameters_model.R +++ b/tests/testthat/test-plot.parameters_model.R @@ -6,7 +6,7 @@ test_that("`plot.see_parameters_model()` works", { skip_if_not_installed("vdiffr") vdiffr::expect_doppelganger( title = "plot.model_parameters_1", - fig = plot(out) + fig = plot(result) ) }) From 9c255eacee3714ad995ffb01cc38319b9dad11e0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 27 Sep 2024 16:39:44 +0200 Subject: [PATCH 04/11] Update plot-model-parameters-1.svg --- .../plot-model-parameters-1.svg | 95 +++++++------------ 1 file changed, 32 insertions(+), 63 deletions(-) diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-1.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-1.svg index ba2c1abe1..626eb9f46 100644 --- a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-1.svg +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-1.svg @@ -21,73 +21,42 @@ - - + + - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - -Random Effects - - - - - - - - - -Fixed Effects - - - -0 -10 -20 -30 - -0 -5 -10 - -Days - -SD (Observations) -SD (Days) -Coefficient + +disp +gear +cyl +wt + +-6 +-4 +-2 +0 +Coefficient plot.model_parameters_1 From 1b73ae78d97dcc44ae63c4d381d0a0da326912e9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 27 Sep 2024 17:05:04 +0200 Subject: [PATCH 05/11] update --- R/plot.parameters_model.R | 12 +++++++++++- tests/testthat/test-plot.parameters_model.R | 20 ++++++++++++++++++++ vignettes/parameters.Rmd | 7 +++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/R/plot.parameters_model.R b/R/plot.parameters_model.R index 884a8110a..99ea3a48e 100644 --- a/R/plot.parameters_model.R +++ b/R/plot.parameters_model.R @@ -613,6 +613,16 @@ plot.see_parameters_model <- function(x, min_ci <- min(x$CI_low, na.rm = TRUE) max_ci <- max(x$CI_high, na.rm = TRUE) + # here we check if all facets have the same scale. If so, we set the scales + # to fixed, otherwise we set them to free_y (in facet_wrap). This removes + # a redundant scale for plots with identical scales. + check_scales <- split(x$Level, x$Group) + if (isTRUE(identical(unname(check_scales[-length(check_scales)]), unname(check_scales[-1])))) { + facet_scales <- "fixed" + } else { + facet_scales <- "free_y" + } + p <- ggplot2::ggplot( x, ggplot2::aes( @@ -641,7 +651,7 @@ plot.see_parameters_model <- function(x, colour = "white", shape = 21 ) + - ggplot2::facet_wrap(~Group, ncol = n_columns) + ggplot2::facet_wrap(~Group, ncol = n_columns, scales = facet_scales) # add coefficients and CIs? if (isTRUE(show_labels)) { diff --git a/tests/testthat/test-plot.parameters_model.R b/tests/testthat/test-plot.parameters_model.R index fa3321224..9896125c4 100644 --- a/tests/testthat/test-plot.parameters_model.R +++ b/tests/testthat/test-plot.parameters_model.R @@ -60,3 +60,23 @@ test_that("`plot.see_parameters_model()` random parameters works", { fig = plot(out, sort = "ascending", show_labels = TRUE, show_intercept = FALSE) ) }) + + +test_that("`plot.see_parameters_model()` random parameters works", { + skip_if_not_installed("vdiffr") + skip_if_not_installed("lme4") + skip_if_not_installed("parameters") + data(sleepstudy, package = "lme4") + + set.seed(12345) + sleepstudy$grp <- sample(1:5, size = 180, replace = TRUE) + model <- lmer( + Reaction ~ Days + (1 | grp) + (1 | Subject), + data = sleepstudy + ) + out <- parameters::model_parameters(model, group_level = TRUE) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_doublerandom", + fig = plot(out) + ) +}) diff --git a/vignettes/parameters.Rmd b/vignettes/parameters.Rmd index 8eb0514eb..1ec2a730f 100644 --- a/vignettes/parameters.Rmd +++ b/vignettes/parameters.Rmd @@ -148,6 +148,13 @@ result <- model_parameters(model2) plot(result) ``` +### Including group levels of random effects + +```{r} +result <- model_parameters(model3, group_level = TRUE) +plot(result) +``` + ### Changing parameter names in the plot By default, `model_parameters()` returns a data frame, where the parameter names are found in the column `Parameter`. These names are used by default in the generated plot: From d58a41ad37c2a2cc1ba9e631075e56ce3eea8c6b Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 27 Sep 2024 17:10:30 +0200 Subject: [PATCH 06/11] fix --- tests/testthat/test-plot.parameters_model.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-plot.parameters_model.R b/tests/testthat/test-plot.parameters_model.R index 9896125c4..a8c2a8cdd 100644 --- a/tests/testthat/test-plot.parameters_model.R +++ b/tests/testthat/test-plot.parameters_model.R @@ -70,7 +70,7 @@ test_that("`plot.see_parameters_model()` random parameters works", { set.seed(12345) sleepstudy$grp <- sample(1:5, size = 180, replace = TRUE) - model <- lmer( + model <- lme4::lmer( Reaction ~ Days + (1 | grp) + (1 | Subject), data = sleepstudy ) From 06f781c2f8833d84706ff31e14b11c2dd86e8a22 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 27 Sep 2024 17:11:14 +0200 Subject: [PATCH 07/11] add snapshot --- .../plot-model-parameters-doublerandom.svg | 191 ++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-doublerandom.svg diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-doublerandom.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-doublerandom.svg new file mode 100644 index 000000000..b20ad27ee --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-doublerandom.svg @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +grp: (Intercept) + + + + + + + + + +Subject: (Intercept) + + + +-100 +-50 +0 +50 +100 + +372 +371 +370 +369 +352 +351 +350 +349 +337 +335 +334 +333 +332 +331 +330 +310 +309 +308 + +5 +4 +3 +2 +1 +Coefficient +Level +plot.model_parameters_doublerandom + + From 15d2ceaf9540696a26b42582b5bfc0773583f002 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 27 Sep 2024 18:19:19 +0200 Subject: [PATCH 08/11] fix --- R/plot.parameters_model.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/plot.parameters_model.R b/R/plot.parameters_model.R index 99ea3a48e..0197d47a4 100644 --- a/R/plot.parameters_model.R +++ b/R/plot.parameters_model.R @@ -54,7 +54,9 @@ plot.see_parameters_model <- function(x, model_attributes <- attributes(x)[!names(attributes(x)) %in% c("names", "row.names", "class")] # user wants to plot random effects (group levels)? - if (isFALSE(model_attributes$ignore_group) && isTRUE(model_attributes$mixed_model)) { + if (isFALSE(model_attributes$ignore_group) && + isTRUE(model_attributes$mixed_model) && + !"describe_posterior" %in% model_attributes$class) { if (missing(show_intercept)) { show_intercept <- TRUE } From 213b62292eef2fca0ad572fb8eb97a3749107fed Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 27 Sep 2024 18:20:03 +0200 Subject: [PATCH 09/11] better --- R/plot.parameters_model.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/plot.parameters_model.R b/R/plot.parameters_model.R index 0197d47a4..3b4cf2b6a 100644 --- a/R/plot.parameters_model.R +++ b/R/plot.parameters_model.R @@ -56,7 +56,7 @@ plot.see_parameters_model <- function(x, # user wants to plot random effects (group levels)? if (isFALSE(model_attributes$ignore_group) && isTRUE(model_attributes$mixed_model) && - !"describe_posterior" %in% model_attributes$class) { + !"brmsfit" %in% model_attributes$model_class) { if (missing(show_intercept)) { show_intercept <- TRUE } From 28625137243290b0aec187c494805dd817b2947f Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 29 Sep 2024 11:12:54 +0200 Subject: [PATCH 10/11] remotes --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 78c8367b1..d836e1090 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -121,4 +121,4 @@ Config/testthat/edition: 3 Config/testthat/parallel: true Config/Needs/website: easystats/easystatstemplate Config/rcmdcheck/ignore-inconsequential-notes: true -Remotes: easystats/performance +Remotes: easystats/performance, easystats/parameters From 049a6e0a8cf4a5da0716d1eee442a197e082456d Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 29 Sep 2024 12:15:11 +0200 Subject: [PATCH 11/11] update snapshots --- .../vdiffr_geoms_coords/geom-point2-works.svg | 20 ++++++------- tests/testthat/test-vdiffr_geoms_coords.R | 30 ++++++++----------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/tests/testthat/_snaps/vdiffr_geoms_coords/geom-point2-works.svg b/tests/testthat/_snaps/vdiffr_geoms_coords/geom-point2-works.svg index 26e4ff8bf..b63d4cd05 100644 --- a/tests/testthat/_snaps/vdiffr_geoms_coords/geom-point2-works.svg +++ b/tests/testthat/_snaps/vdiffr_geoms_coords/geom-point2-works.svg @@ -39,6 +39,16 @@ + + + + + + + + + + @@ -213,16 +223,6 @@ Petal.Width Sepal.Length - - - - - - - - - - diff --git a/tests/testthat/test-vdiffr_geoms_coords.R b/tests/testthat/test-vdiffr_geoms_coords.R index 845b95486..ed9f0a724 100644 --- a/tests/testthat/test-vdiffr_geoms_coords.R +++ b/tests/testthat/test-vdiffr_geoms_coords.R @@ -1,36 +1,32 @@ test_that("geom and coord functions work correctly", { - skip_if_not_installed("poorman") - suppressPackageStartupMessages(library(poorman)) - + skip_if_not_installed("ggplot2") # coord_radar() ------------------ - data <- iris %>% - group_by(Species) %>% - summarise(across(everything(), mean)) %>% - datawizard::reshape_longer(c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")) + data <- aggregate(iris[1:4], list(Species = iris$Species), mean) + data <- datawizard::reshape_longer(data, c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")) set.seed(123) vdiffr::expect_doppelganger( title = "coord_radar() works", - fig = ggplot( + fig = ggplot2::ggplot( data, - aes( + ggplot2::aes( x = name, y = value, color = Species, group = Species ) ) + - geom_polygon(fill = NA, linewidth = 2) + + ggplot2::geom_polygon(fill = NA, linewidth = 2) + coord_radar(start = -pi / 4) ) # geom_point2() ---------------------- - normal <- ggplot(iris, aes(x = Petal.Width, y = Sepal.Length)) + - geom_point(size = 8, alpha = 0.3) + + normal <- ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Width, y = Sepal.Length)) + + ggplot2::geom_point(size = 8, alpha = 0.3) + theme_modern() - new <- ggplot(iris, aes(x = Petal.Width, y = Sepal.Length)) + + new <- ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Width, y = Sepal.Length)) + geom_point2(size = 8, alpha = 0.3) + theme_modern() @@ -45,7 +41,7 @@ test_that("geom and coord functions work correctly", { set.seed(123) vdiffr::expect_doppelganger( title = "`geom_poolpoint()` works - 1", - fig = ggplot(iris, aes(x = Petal.Width, y = Sepal.Length, color = Species)) + + fig = ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Width, y = Sepal.Length, color = Species)) + geom_poolpoint(label = rownames(iris)) + scale_color_flat_d() + theme_modern() @@ -54,7 +50,7 @@ test_that("geom and coord functions work correctly", { set.seed(123) vdiffr::expect_doppelganger( title = "`geom_poolpoint()` works - 2", - fig = ggplot(iris, aes(x = Petal.Width, y = Sepal.Length, color = Species)) + + fig = ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Width, y = Sepal.Length, color = Species)) + geom_pooljitter(label = rownames(iris)) + scale_color_flat_d() + theme_modern() @@ -65,7 +61,7 @@ test_that("geom and coord functions work correctly", { set.seed(123) vdiffr::expect_doppelganger( title = "geom_violindot() works", - fig = ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) + + fig = ggplot2::ggplot(iris, ggplot2::aes(x = Species, y = Sepal.Length, fill = Species)) + geom_violindot() + theme_modern() ) @@ -75,7 +71,7 @@ test_that("geom and coord functions work correctly", { set.seed(123) vdiffr::expect_doppelganger( title = "geom_violinhalf() works", - fig = ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) + + fig = ggplot2::ggplot(iris, ggplot2::aes(x = Species, y = Sepal.Length, fill = Species)) + geom_violinhalf() + theme_modern() + scale_fill_material_d()