R/plotEDY.R

Defines functions plot.EDY

Documented in plot.EDY

#' Plot EDY objects.
#'
#' @title Plot EDY objects
#' @param x An EDY object generated by the function \code{getEDY}.
#' 
#' @import ggplot2
#' @export plot.EDY 
#' @return A scatter plot in which \code{y axis} represents mean gene expression
#'   in chromosome Y divided by mean gene expression in the rest of the genome
#'   and each dot represents an individual. Individuals with extreme
#'   downregulation of chromosome Y are coloured in light blue and labeled
#'   with their identifiers. Normal individuals are coloured in red. The dashed
#'   line indicates the threshold from which down EDY is considered.

plot.EDY <- function(x, ...){
  edy <- data.frame(x$EDYcontinuous, 1:length(x$EDYcontinuous))
  ggplot(edy, aes(x = edy[,2], y = edy[,1], color = x$EDY)) + 
    geom_point(size = 1.5) +
    labs( y = "Gene expression ChrY / Autosomes", x = "Individuals") +
    theme(plot.title = element_text(hjust = 0.5), axis.text.x = element_blank(), 
          axis.ticks.x = element_blank(), legend.title = element_blank()) +
    scale_colour_discrete(labels=c("normal", "EDY")) +
    scale_y_continuous(breaks = pretty(edy[,1], n = 5)) +
    geom_text(aes(label = ifelse(edy[,1] < x$threshold, as.character(rownames(edy)), '')), hjust = 0, 
              vjust = 1, size = 3) +
    geom_hline(yintercept = x$threshold, linetype = "dashed")
}
isglobal-brge/EDY documentation built on Jan. 24, 2020, 3:21 a.m.