diff --git a/NEWS.md b/NEWS.md index 3f3121a..e2f4486 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ * include the argument `which_plots` in the `plot.lcc` function so that one can specify which plots should be plotted +* include the argument `n_item_consensus` in the `plot.lcc` function so that one + can specify how many item consensus plots should be plotted in one plot # longmixr 1.0.0 diff --git a/R/plot.lcc.R b/R/plot.lcc.R index d66f752..287ddc4 100644 --- a/R/plot.lcc.R +++ b/R/plot.lcc.R @@ -9,6 +9,8 @@ #' of clusters, \code{"CDF"}, \code{"delta"}, \code{"cluster_tracking"}, #' \code{"item_consensus"} or \code{"cluster_consensus"}. When you want to plot #' all consensus matrices and the legend, you can just use \code{"consensusmatrix"}. +#' @param n_item_consensus determines how many item consensus plots are plotted +#' together in one plot before a new plot is used; the default is \code{3}. #' @param ... additional parameters for plotting; currently not used #' #' @return Plots the following plots (when selected):\tabular{ll}{ @@ -35,10 +37,12 @@ plot.lcc <- function(x, color_palette = NULL, which_plots = "all", + n_item_consensus = 3, ...) { checkmate::assert_class(x, "lcc") checkmate::assert_character(color_palette, null.ok = TRUE) + checkmate::assert_int(n_item_consensus, lower = 1) # determine the possible consensus matrices possible_consensusmatrix <- paste0("consensusmatrix_", @@ -178,7 +182,7 @@ plot.lcc <- function(x, cci <- rbind() sumx <- list() colors_arr <- c() - old_par <- par(mfrow = c(3, 1), mar = c(4, 3, 2, 0)) + old_par <- par(mfrow = c(n_item_consensus, 1), mar = c(4, 3, 2, 0)) on.exit(par(old_par)) # tk is the number of predefined clusters for (tk in seq(from = 2, to = length(x), by = 1)) { diff --git a/man/plot.lcc.Rd b/man/plot.lcc.Rd index 473f37f..bffa53c 100644 --- a/man/plot.lcc.Rd +++ b/man/plot.lcc.Rd @@ -4,7 +4,7 @@ \alias{plot.lcc} \title{Plot a longitudinal consensus clustering} \usage{ -\method{plot}{lcc}(x, color_palette = NULL, which_plots = "all", ...) +\method{plot}{lcc}(x, color_palette = NULL, which_plots = "all", n_item_consensus = 3, ...) } \arguments{ \item{x}{\code{lcc} object (output from \code{\link{longitudinal_consensus_cluster}})} @@ -13,12 +13,15 @@ \item{which_plots}{determine which plots should be plotted; the default is \code{"all"}. Alternatively, a combination of the following values can be specified to plot -only certain plots of the below mentioned plots: \code{"consensusmatrix_legend"}, +only some of the below mentioned plots: \code{"consensusmatrix_legend"}, \code{"consensusmatrix_x"} where \code{x} is replaced by the corresponding number of clusters, \code{"CDF"}, \code{"delta"}, \code{"cluster_tracking"}, \code{"item_consensus"} or \code{"cluster_consensus"}. When you want to plot all consensus matrices and the legend, you can just use \code{"consensusmatrix"}.} +\item{n_item_consensus}{determines how many item consensus plots are plotted +together in one plot before a new plot is used; the default is \code{3}.} + \item{...}{additional parameters for plotting; currently not used} } \value{ diff --git a/tests/testthat/_snaps/lcc_plot/plot_lcc_output_item_consenus_1.png b/tests/testthat/_snaps/lcc_plot/plot_lcc_output_item_consenus_1.png new file mode 100644 index 0000000..1a577bb Binary files /dev/null and b/tests/testthat/_snaps/lcc_plot/plot_lcc_output_item_consenus_1.png differ diff --git a/tests/testthat/test_lcc_plot.R b/tests/testthat/test_lcc_plot.R index 3b964b3..fc3b917 100644 --- a/tests/testthat/test_lcc_plot.R +++ b/tests/testthat/test_lcc_plot.R @@ -73,3 +73,14 @@ test_that("the which_plots argument is correct", { expect_snapshot_file(save_png(plot(clustering, which_plots = c("CDF", "cluster_tracking"))), "plot_lcc_output_cdf_cluster_tracking.png") }) + +test_that("the n_item_consensus argument is correct", { + expect_error(plot(clustering, n_item_consensus = "test")) + expect_error(plot(clustering, n_item_consensus = -1)) + + skip_on_ci() + # only the last plot (with k=3) is recorded + expect_snapshot_file(save_png(plot(clustering, which_plots = "item_consensus", + n_item_consensus = 1)), + "plot_lcc_output_item_consenus_1.png") +})