diff --git a/DESCRIPTION b/DESCRIPTION index c65b20e1..836da18b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -98,6 +98,8 @@ Collate: 'DEPRECATED-ggplot2.R' 'DEPRECATED-hy_options.R' 'DEPRECATED-isample.R' + 'mark_groups_in_dendrogram.R' + 'DEPRECATED-mark.dendrogram.R' 'mark_peak.R' 'DEPRECATED-markpeak.R' 'cov_pooled.R' @@ -180,7 +182,6 @@ Collate: 'plot_map.R' 'levelplot.R' 'map_identify.R' - 'mark_groups_in_dendrogram.R' 'mean_sd.R' 'merge.R' 'mergeextra.R' diff --git a/NEWS.md b/NEWS.md index bc3d3c30..dfa57859 100644 --- a/NEWS.md +++ b/NEWS.md @@ -36,6 +36,7 @@ `hy.getOptions()` | `hy_get_options()` | #21 `hy.setOptions()` | `hy_set_options()` | #21 `makeraster()` | `raster_make()` | #47 + `mark.dendrogram()` | `mark_groups_in_dendrogram()` | #43 `markpeak()` | `mark_peak()` | #44 `matlab.dark.palette()` | `palette_matlab_dark()` | cbeleites/hyperSpec#299, cbeleites/hyperSpec#299, @sangttruong `matlab.palette()` | `palette_matlab()` | cbeleites/hyperSpec#208, cbeleites/hyperSpec#299, @sangttruong diff --git a/R/DEPRECATED-mark.dendrogram.R b/R/DEPRECATED-mark.dendrogram.R new file mode 100644 index 00000000..edd54043 --- /dev/null +++ b/R/DEPRECATED-mark.dendrogram.R @@ -0,0 +1,35 @@ +#' @name DEPRECATED-mark.dendrogram +#' @concept deprecated +#' +#' @title (DEPRECATED) +#' Identifying spectra and spectral data points +#' +#' @description +#' These \pkg{hyperSpec} functions are **deprecated** and not maintained any +#' more. You should not use these. +#' Currently they are present due to back-compatibility reasons and will be +#' removed in the next release of the package. +#' Please, use the suggested alternative functions instead: +#' +#' - [hyperSpec::mark_groups_in_dendrogram()] +#' +#' +#' @param ... arguments to [hyperSpec::mark_groups_in_dendrogram()]. +#' +#' @include mark_groups_in_dendrogram.R +#' @export +mark.dendrogram <- function(...) { + hySpc_deprecated("mark_groups_in_dendrogram") + mark_groups_in_dendrogram(...) +} + + +# Unit tests ----------------------------------------------------------------- + +hySpc.testthat::test(mark.dendrogram) <- function() { + context("Deprecated functions") + + test_that("mark.dendrogram() is deprecated", { + expect_error(expect_warning(mark.dendrogram(), "deprecated")) + }) +} diff --git a/R/mark_groups_in_dendrogram.R b/R/mark_groups_in_dendrogram.R index 186e46fa..46bc9f20 100644 --- a/R/mark_groups_in_dendrogram.R +++ b/R/mark_groups_in_dendrogram.R @@ -1,7 +1,10 @@ +#' @title Mark groups in [stats::hclust()] dendrograms +#' #' Groups are marked by colored rectangles as well as by their levels #' #' The dendrogram should be plotted separately, see the example. -#' @title Mark groups in [stats::hclust()] dendrograms +#' +#' #' @param dendrogram the dendrogram #' @param groups factor giving the the groups to mark #' @param col vector with colors for each group @@ -13,40 +16,45 @@ #' @param label side label see example #' @param label.right should the side labels be at the right side? #' @param ... handed to [graphics::rect()] and [graphics::text()] +#' #' @author Claudia Beleites #' #' @concept plotting #' @concept plotting tools #' #' @export -#' @rdname mark.dendrogram +#' @rdname mark_groups_in_dendrogram #' @examples #' #' dend <- hclust(dist_pearson(laser[[]])) #' par(xpd = TRUE, mar = c(5.1, 4, 4, 3)) # allows plotting into the margin #' plot(dend, hang = -1, labels = FALSE) #' -#' ## mark clusters +#' # mark clusters #' clusters <- as.factor(cutree(dend, k = 4)) #' levels(clusters) <- LETTERS[1:4] -#' mark.dendrogram(dend, clusters, label = "cluster") +#' mark_groups_in_dendrogram(dend, clusters, label = "cluster") #' -#' ## mark independent factor -#' mark.dendrogram(dend, as.factor(laser[, , 405.36] > 11000), +#' # mark independent factor +#' mark_groups_in_dendrogram(dend, as.factor(laser[, , 405.36] > 11000), #' pos.marker = -0.02, pos.text = -0.03 #' ) #' -#' ## mark continuous variable: convert it to a factor and omit labels -#' mark.dendrogram(dend, cut(laser[[, , 405.36]], 100), palette_alois(100), -#' pos.marker = -.015, text.col = NA, +#' # mark continuous variable: convert it to a factor and omit labels +#' mark_groups_in_dendrogram(dend, cut(laser[[, , 405.36]], 100), +#' palette_alois(100), pos.marker = -.015, text.col = NA, #' label = expression(I[lambda == 405.36 ~ nm]), label.right = FALSE #' ) #' @importFrom utils head tail -mark.dendrogram <- function(dendrogram, groups, col = seq_along(unique(groups)), +mark_groups_in_dendrogram <- function(dendrogram, groups, + col = seq_along(unique(groups)), pos.marker = 0, height = 0.025 * max(dendrogram$height), pos.text = -2.5 * height, - border = NA, text.col = "black", label, label.right = TRUE, + border = NA, + text.col = "black", + label, + label.right = TRUE, ...) { if (!is.factor(groups)) { groups <- as.factor(groups)