R/mark_peak.R

Defines functions mark_peak

#' Mark peak
#'
#' Marks location of the *first* spectrum at the data point closest to the
#' specified position on the current plot.
#'
#' @param spc the `hyperSpec` object
#' @param xpos position of the peak(s) in current x-axis units
#' @param col color of the markers and text
#'
#'
#' @author R. Kiselev
#'
#' @concept plotting
#' @concept plotting tools
#'
#' @export
#' @examples
#' plot(faux_cell[7])
#' mark_peak(faux_cell[7], 1662)
mark_peak <- function(spc, xpos, col = "red") {
  assert_hyperSpec(spc)
  validObject(spc)

  plot(spc[1, , xpos], add = T, lines.args = list(type = "p"), col = col)
  text(
    x = xpos, y = spc[[1, , xpos]], col = col, labels = sprintf("<- %.1f", xpos),
    adj = c(-0.2, 0.37), srt = 90, cex = 0.75
  )
}
r-hyperspec/hyperSpec documentation built on May 31, 2024, 5:53 p.m.