R/clusterPlot.R

Defines functions clusterPlot

Documented in clusterPlot

#' Dendrogram of sample clustering
#'
#' Dendrogram of sample clustering
#'
#' @param counts a numeric matrix of raw or transformed counts
#' @param out \code{TRUE} to export the figure
#' @param versionName versionName of the project
#' @return A dendrogram
#' @author Marie-Agnes Dillies and Hugo Varet

# created Sept 13th, 2012
# modified Oct 30th, 2012
# modified Jan 16th, 2013 (pdf)
# modified Sept 19th, 2013 (adapted for DESeq2)
# modified Sept 20th, 2013 (estimateDispersions now run in the main script)
# modified Sept 30th, 2013 (add type.norm)
# modified Oct 14th, 2013 (type.norm modifi? en type.trans)
# modified Nov 14th, 2013 (first arg is now counts instead of dds)
# modified Feb 25th, 2014 (added hang = -1 in plot.hclust())
# modified Mar 21st, 2014 (removed outputfile argument)
# modified Apr 16th, 2014 (replaced "ward" by "ward.D" in hclust() due to R 3.1.0 (package stats))
# modified Aug 5th, 2014 (removed graphDir and type.trans argument)
# modified August 26th, 2019 (ggplot2)

clusterPlot <- function(counts, out = TRUE, versionName="."){
  if (out) pdf(file=paste0("figures/", versionName, "-cluster.pdf"))
  hc <- hclust(dist(t(counts)), method="ward.D")
  print(ggdendrogram(hc, theme_dendro=FALSE) +
    xlab("Samples") +
    ylab("Height") +
    ggtitle(paste0(versionName, " - Cluster dendrogram\nEuclidean distance, Ward criterion")) +
    theme(axis.text.x=element_text(angle=90, hjust=1, vjust=0.5),
          axis.text.y=element_text(angle=0)) +
    scale_y_continuous(expand=expansion(mult=c(0.01, 0.05))))
  if (out) dev.off()
}
biomics-pasteur-fr/RNADiff documentation built on Aug. 27, 2020, 12:44 a.m.