Skip to content

Commit

Permalink
Merge branch 'develop' into feature-38/rename-functions-2
Browse files Browse the repository at this point in the history
  • Loading branch information
GegznaV committed Dec 14, 2021
2 parents 6b147ea + 20131c8 commit 7561cfa
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions R/DEPRECATED-mark.dendrogram.R
Original file line number Diff line number Diff line change
@@ -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"))
})
}
30 changes: 19 additions & 11 deletions R/mark_groups_in_dendrogram.R
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 7561cfa

Please sign in to comment.