R/MQ_evidence_ppm_error_boxplot.R

#' Plot ppm error intensities for individual experiments using boxplots
#'
#' @description Make boxplots for ppm error for the individual experiments. Optionally
#' you can color them by their group_id (see color_groups argument)
#'
#' @return Boxplots of log10 peptidide intensity.
#'
#' @param x The evidence.txt file from MaxQuant output.
#' @param color_groups Logical. If set to TRUE, colors will be assigned to the boxplots based on the
#' my_groups column. Use add_groups function first to create the \code{\link{add_groups}} column. Default
#' value is FALSE, which will give boxplots with the same color.
#'
#' @example
#' MQ_evidence_intensity_boxplot(data, color_groups = TRUE)
#'
#' @export

MQ_evidence_ppm_error_boxplot <- function(x, color_groups = FALSE) {
  names(x) <- tolower(names(x))
  if (color_groups == TRUE) {
    if (!("my_groups" %in% names(x))) {
      stop("Use 'add_groups' function first to assign groups based on the 'Experiment' name.", .call = FALSE)
    }
    print("Experiments will be colored based on the defined groups.")
    p <- ggplot(x, aes(x = experiment, y = mass.error..ppm., fill = my_groups))

  } else {
    p <- ggplot(x, aes(x = experiment, y = mass.error..ppm.))
  }
  p <- p + geom_boxplot()
  p <- p + theme_bw()
  p <- p + xlab("Sample")
  p <- p + ylab("Peptide ppm error")
  p <- p + geom_hline(yintercept = 0)
  p <- p + ggtitle("ppm error distribution per Experiment.")
  p <- p + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
  p <- p + theme(legend.position = "bottom")
  p <- p + theme(legend.key.size = unit(0.2, "cm"))
  p <- p + theme(legend.text = element_text(size = 8))
  print(p)
}
tkostas/viewMQ documentation built on May 6, 2019, 6:02 p.m.