a b/R/DIscBIO-generic-plotGap.R
1
#' @title Plotting Gap Statistics
2
#' @export
3
#' @rdname plotGap
4
#' @param object \code{DISCBIO} class object.
5
#' @param y_limits 2-length numeric vector with the limits for the gap plot
6
#' @return A plot of the gap statistics
7
setGeneric(
8
  "plotGap", function(object, y_limits = NULL) standardGeneric("plotGap")
9
)
10
11
#' @rdname plotGap
12
setMethod(
13
  f = "plotGap",
14
  signature = "DISCBIO",
15
  definition = function(object, y_limits) {
16
    if (length(object@kmeans$kpart) == 0) {
17
      stop("run clustexp before plotgap")
18
    }
19
    gap <- object@kmeans$gap
20
    if (is.null(y_limits)) {
21
      y_lo <- min(gap$Tab[, "gap"]) - 1 * max(gap$Tab[, "SE.sim"])
22
      y_up <- max(gap$Tab[, "gap"]) + 1 * max(gap$Tab[, "SE.sim"])
23
      y_limits <- c(y_lo, y_up)
24
    }
25
    plot(
26
      gap,
27
      las = 1, ylim = y_limits, main = "Gap Statistics"
28
    )
29
  }
30
)