Skip to content

Commit

Permalink
add the ability to determine how many item-consensus plots are plotte…
Browse files Browse the repository at this point in the history
…d in one plot before a new plot is used
  • Loading branch information
jonas-hag committed Mar 12, 2023
1 parent 44ef039 commit 0b67419
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion R/plot.lcc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}{
Expand All @@ -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_",
Expand Down Expand Up @@ -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)) {
Expand Down
7 changes: 5 additions & 2 deletions man/plot.lcc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions tests/testthat/test_lcc_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})

0 comments on commit 0b67419

Please sign in to comment.