diff --git a/.gitignore b/.gitignore index 7ab91810d..0bc25ec54 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,5 @@ revdep/checks.noindex revdep/library.noindex revdep/data.sqlite CRAN-SUBMISSION + +*.bak diff --git a/R/plot.parameters_model.R b/R/plot.parameters_model.R index 49076abe6..57b9eb85b 100644 --- a/R/plot.parameters_model.R +++ b/R/plot.parameters_model.R @@ -410,12 +410,12 @@ plot.see_parameters_model <- function( if (isTRUE(sort) || (!is.null(sort) && sort == "ascending")) { x$Parameter <- factor( x$Parameter, - levels = rev(unique(x$Parameter)[order(x$Coefficient)]) + levels = unique(x$Parameter)[order(x$Coefficient)] ) } else if (!is.null(sort) && sort == "descending") { x$Parameter <- factor( x$Parameter, - levels = unique(x$Parameter)[order(x$Coefficient)] + levels = rev(unique(x$Parameter)[order(x$Coefficient)]) ) } else { # sort coefficients as they appear in the classical summary output by default @@ -807,10 +807,10 @@ plot.see_parameters_model <- function( if (isTRUE(sort) || (!is.null(sort) && sort == "ascending")) { x$Level <- factor( x$Level, - levels = rev(unique(x$Level)[order(x$Coefficient)]) + levels = 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)]) + x$Level <- factor(x$Level, levels = rev(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))) 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 index 48c3f396e..db0b2b123 100644 --- 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 @@ -28,96 +28,96 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -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] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +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] @@ -129,96 +129,96 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -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] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +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] @@ -246,43 +246,43 @@ 0 50 -337 -330 -331 -352 -333 -372 -332 -351 -369 -308 -371 -335 -334 -350 -349 -370 -310 -309 +309 +310 +370 +349 +350 +334 +335 +371 +308 +369 +351 +332 +372 +333 +352 +331 +330 +337 -337 -330 -331 -352 -333 -372 -332 -351 -369 -308 -371 -335 -334 -350 -349 -370 -310 -309 +309 +310 +370 +349 +350 +334 +335 +371 +308 +369 +351 +332 +372 +333 +352 +331 +330 +337 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 index 90a3a03f0..1018365b9 100644 --- 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 @@ -28,96 +28,96 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -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] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +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] @@ -129,96 +129,96 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -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] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +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] @@ -256,24 +256,24 @@ 100 150 -337 -330 -331 -352 -333 -372 -332 -351 -369 -308 -371 -335 -334 -350 -349 -370 -310 -309 +309 +310 +370 +349 +350 +334 +335 +371 +308 +369 +351 +332 +372 +333 +352 +331 +330 +337 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 index f277c1d03..c50c03686 100644 --- 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 @@ -28,96 +28,96 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -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] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +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] @@ -137,24 +137,24 @@ 10 20 -308 -337 -350 -370 -352 -372 -349 -334 -369 -333 -332 -371 -351 -331 -330 -310 -309 -335 +335 +309 +310 +330 +331 +351 +371 +332 +333 +369 +334 +349 +372 +352 +370 +350 +337 +308 Coefficient Level plot.model_parameters_random_6 diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-sort-ascending.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-sort-ascending.svg new file mode 100644 index 000000000..ff95933cc --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-sort-ascending.svg @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-3.79 [-6.01, -1.57] +-1.78 [-3.04, -0.52] +-0.49 [-2.11, 1.13] +0.01 [-0.02, 0.03] + + + +wt +cyl +gear +disp + +-5 +0 +Coefficient +plot.model_parameters_sort_ascending + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-sort-descending.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-sort-descending.svg new file mode 100644 index 000000000..14c2307d8 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-sort-descending.svg @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-3.79 [-6.01, -1.57] +-1.78 [-3.04, -0.52] +-0.49 [-2.11, 1.13] +0.01 [-0.02, 0.03] + + + +disp +gear +cyl +wt + +-5 +0 +Coefficient +plot.model_parameters_sort_descending + + diff --git a/tests/testthat/test-plot.parameters_model.R b/tests/testthat/test-plot.parameters_model.R index abbe59ec9..a3784f628 100644 --- a/tests/testthat/test-plot.parameters_model.R +++ b/tests/testthat/test-plot.parameters_model.R @@ -14,6 +14,34 @@ test_that("`plot.see_parameters_model()` works", { }) +test_that("`plot.see_parameters_model()` sort parameter works for fixed effects", { + m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars) + result <- parameters::model_parameters(m) + # Test sort = TRUE (should be same as ascending) + p1 <- plot(result, sort = TRUE) + expect_s3_class(p1, "gg") + + # Test sort = "ascending" + p2 <- plot(result, sort = "ascending") + expect_s3_class(p2, "gg") + + # Test sort = "descending" + p3 <- plot(result, sort = "descending") + expect_s3_class(p3, "gg") + # Test with labels + p4 <- plot(result, sort = "ascending", show_labels = TRUE) + expect_s3_class(p4, "gg") + vdiffr::expect_doppelganger( + title = "plot.model_parameters_sort_ascending", + fig = plot(result, sort = "ascending", show_labels = TRUE) + ) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_sort_descending", + fig = plot(result, sort = "descending", show_labels = TRUE) + ) +}) + + test_that("`plot.see_parameters_model()` errors for anova tables", { skip_if_not_installed("parameters") data(iris)