R/plotRawCount.R

Defines functions plotRawCount

Documented in plotRawCount

#' Plot the distribution of the raw signal intensity (raw counts) on each plate
#'
#' This function generates a box plot to show the raw signal distribution on each plate.
#'
#' @param screenData  a data frame containing screen date generated by readScreen() function
#' @param topN an integer value or NULL, indicating how many plates should be included in the plot If NULL, all the plates are included
#' @param ifLog10 a logical value, whether to perform log10 transformation
#' @import dplyr ggplot2
#' @return a ggplot object
#' @export
#' @examples
#' # load processed data
#' data('screenData')
#'
#' # plot the raw ATP counts on all plates
#' plotRawCount(screenData)
#' # Please see the vignette for more information.


plotRawCount <- function(screenData, topN = NULL, ifLog10 = FALSE) {

  # only plot top N plate or all plate?
  if (!is.null(topN)) {
    allNames <- unique(screenData$fileName)
    plotTab <- dplyr::filter(screenData, fileName %in% allNames[seq_len(min(length(allNames),
                                                                            topN))])

  } else {
    plotTab <- screenData

  }

  if (ifLog10) {
    plotTab <- dplyr::mutate(plotTab, value = log10(value))
  }

  plotTab <- dplyr::mutate(plotTab, fileName = factor(fileName, levels = rev(unique(fileName))))

  g <- ggplot(plotTab, aes(x = fileName, y = value)) +
    geom_jitter(width = 0.3, alpha = 0.3,color = "grey50") +
    geom_boxplot(fill = NA, color = "royalblue2", outlier.shape = NA) +
    coord_flip() + theme_bw() + xlab("file names") +
    ylab(ifelse(ifLog10, "log10 (raw counts)", "raw counts"))

}
lujunyan1118/DrugScreenExplorer_dev documentation built on Dec. 21, 2021, 12:42 p.m.