R/plot_ExpSd.R

Defines functions plot_ExpSd

Documented in plot_ExpSd

#' @title Plot the stadard deviation against average experssion of genes/microRNAs.
#'
#' @description \code{plot_ExpSd} generates a scatter plot and fits with a smoothing line to data.
#'
#' @param data A matrix, the normalized gene/microRNA expression dataset, should be a numeric matrix, with rows referring to genes/microRNAs and columns to samples.
#' @param title The title of the figure.
#' @param fitline Logical, TRUE to fit a smoothing line to the data.
#'
#' @return A scatter plot fitted with a smoothing curve.
#'
#' @seealso \code{\link[stats]{loess}} for locally weighted smoothing.
#'
#' @export plot_ExpSd
#'
#' @examples
#' # prepare an adjacency matrix
#' set.seed(3)
#' data.m <- matrix(rnorm(500), nrow = 100, ncol = 5)
#'
#' # generate the network
#' plot_ExpSd(data.m, title = 'examples')


plot_ExpSd <- function(data, title, fitline = FALSE){
    
    mean.v <- rowMeans(data)
    sd.v <- apply(data, 1, sd)

    p <- ggplot(data = data.frame(AveExp = mean.v, SD = sd.v), aes(x = AveExp, y = SD)) + geom_point(alpha = 0.6) + theme_bw() + geom_smooth(method = 'loess', se = FALSE) + ggtitle(title)
    if(fitline) p <- p + geom_smooth(method = 'loess', se = FALSE)
    
    plot(p)
}
YC3/mirNet documentation built on Sept. 3, 2020, 3:25 a.m.