R/plot_xic.R

Defines functions plot_xic

Documented in plot_xic

#' Plot Extracted Ion Chromatogram
#'
#' Take a table of rt and intensity coordinates, return a list of gg objects
#' representing a chromatogram with baseline-corrected area filled.
#' @param coords rt and intensity coords
#' @keywords plot spectra match cosine
#' @export
#' @examples
#' xic_gg <- plot_xic(chromdata %>% filter(roi == 2))
#'
plot_xic <- function(coords, alpha = 0.4){
  coords <- coords %>%
    arrange(rt)
  gg = list(
    # plot the line
    geom_line(data = coords, aes(x = rt, y = intensity)),
    # and the baselined area
    geom_polygon(data = coords, aes(x = rt, y = intensity), alpha = alpha),
    #geom_area(data = coords, aes(x = rt, y = intensity), alpha = alpha),
    #geom_area(data = bind_rows(head(coords, 1), tail(coords, 1)), aes(x = rt, y = intensity), fill = "white"),
    theme_pubr()
  )
  return(gg)
}
octopode/tidychrom documentation built on Nov. 2, 2022, 1:32 a.m.