diff --git a/R/plot.R b/R/plot.R index d52a2da..c861027 100644 --- a/R/plot.R +++ b/R/plot.R @@ -271,7 +271,7 @@ plot_dynamiteformula_ggplot <- function(g, vertex_size, label_size) { #' is provided, the same limit is used for all parameters. If a vector is #' supplied, the first element defines the maximum number of time-invariant #' parameters to plot and the second the maximum number of time-varying -#' parameters to plot. The defaults values are 50 for time-invariant +#' parameters to plot. The defaults values are 20 for time-invariant #' parameters and 3 for time-varying parameters. The default value is 5 #' for `plot_type == "trace"`. #' @param ... Not used.. @@ -372,6 +372,11 @@ plot.dynamitefit <- function(x, plot_type = c("default", "trace"), groups = groups, probs = c(level, 1 - level) ) + coefs <- ifelse_( + is.null(types) && is.null(parameters), + coefs[coefs$type %in% default_types, ], + coefs + ) p_fixed <- plot_fixed( coefs, level, @@ -463,12 +468,11 @@ plot_trace <- function(x, types, parameters, responses, #' @inheritParams plot.dynamitefit #' @noRd plot_fixed <- function(coefs, level, alpha, scales, n_params) { - coefs <- coefs[coefs$type %in% intersect(fixed_types, default_types), ] coefs <- coefs[is.na(coefs$time), ] if (nrow(coefs) == 0L) { return(NULL) } - coefs <- filter_params(coefs, n_params, 50) + coefs <- filter_params(coefs, n_params, 20) n_coefs <- nrow(coefs) coefs$parameter <- glue::glue( "{coefs$parameter}_{coefs$category}_{coefs$group}" @@ -526,7 +530,6 @@ plot_fixed <- function(coefs, level, alpha, scales, n_params) { #' @inheritParams plot.dynamitefit #' @noRd plot_varying <- function(coefs, level, alpha, scales, n_params) { - coefs <- coefs[coefs$type %in% intersect(varying_types, default_types), ] coefs <- coefs[!is.na(coefs$time), ] if (nrow(coefs) == 0L) { return(NULL) @@ -603,10 +606,10 @@ filter_params <- function(x, n_params, n_params_default) { onlyif( !n_params_set && !all(keep_params), warning_(c( - "Number of parameters to be plotted ({n_u_params}) exceeds the - maximum number of parameters ({n_params}). The remaining parameters will - not be plotted.", - `i` = "Please increase {.arg n_params} to plot more parameters." + "Number of parameters to be plotted ({n_vars}) exceeds the + maximum number of parameters ({n_params}). The remaining parameters + will not be plotted.", + `i` = "Please increase {.arg n_params} to plot more parameters." )) ) } else { @@ -625,10 +628,10 @@ filter_params <- function(x, n_params, n_params_default) { !n_params_set && !all(keep_type_params), warning_(c( "Number of parameters to be plotted ({n_u_params}) exceeds the - maximum number of parameters ({max_params}) for parameters - of type {.var type}. The remaining parameters of this type will - not be plotted.", - `i` = "Please increase {.arg n_params} to plot more parameters." + maximum number of parameters ({max_params}) for parameters + of type {.var {type}}. The remaining parameters of this type will + not be plotted.", + `i` = "Please increase {.arg n_params} to plot more parameters." )) ) } diff --git a/man/plot.dynamitefit.Rd b/man/plot.dynamitefit.Rd index a7c9180..f3fab3d 100644 --- a/man/plot.dynamitefit.Rd +++ b/man/plot.dynamitefit.Rd @@ -65,7 +65,7 @@ specifying the maximum number of parameters to plot. If a single value is provided, the same limit is used for all parameters. If a vector is supplied, the first element defines the maximum number of time-invariant parameters to plot and the second the maximum number of time-varying -parameters to plot. The defaults values are 50 for time-invariant +parameters to plot. The defaults values are 20 for time-invariant parameters and 3 for time-varying parameters. The default value is 5 for \code{plot_type == "trace"}.} diff --git a/tests/testthat/test-output.R b/tests/testthat/test-output.R index 3076714..6a0843f 100644 --- a/tests/testthat/test-output.R +++ b/tests/testthat/test-output.R @@ -106,7 +106,6 @@ test_that("trace type plot works", { ) }) - test_that("combining plots works", { expect_error( plot(gaussian_example_fit, type = c("alpha", "beta")), @@ -230,7 +229,7 @@ test_that("deltas can be plotted", { test_that("nus can be plotted", { expect_error( - plot(gaussian_example_fit, types = "nu"), + plot(gaussian_example_fit, types = "nu", n_params = 10), NA ) }) diff --git a/tests/testthat/test-warnings.R b/tests/testthat/test-warnings.R index fba37b3..c718689 100644 --- a/tests/testthat/test-warnings.R +++ b/tests/testthat/test-warnings.R @@ -292,6 +292,29 @@ test_that("windows and old rstan warns on attach", { ) }) +# Plot warnings ----------------------------------------------------------- + +test_that("too many parameters warns in plot", { + expect_warning( + plot(gaussian_example_fit, types = "nu"), + paste0( + "Number of parameters to be plotted \\(50\\) exceeds the maximum ", + "number of parameters \\(20\\) for parameters of type `nu`\\. ", + "The remaining parameters of this type will not be plotted\\.\n", + "i Please increase `n_params` to plot more parameters\\." + ) + ) + expect_warning( + plot(gaussian_example_fit, types = "nu", plot_type = "trace"), + paste0( + "Number of parameters to be plotted \\(50\\) exceeds the maximum ", + "number of parameters \\(5\\)\\. ", + "The remaining parameters will not be plotted\\.\n", + "i Please increase `n_params` to plot more parameters\\." + ) + ) +}) + # Deprecated -------------------------------------------------------------- test_that("deprecated warn", { @@ -304,7 +327,7 @@ test_that("deprecated warn", { "'plot_deltas' is deprecated" ) expect_warning( - plot_nus(gaussian_example_fit), + plot_nus(gaussian_example_fit, n_params = 10), "'plot_nus' is deprecated" ) expect_warning(