R/plot.ptSimilarity.r

Defines functions plot.ptSimilarity

Documented in plot.ptSimilarity

#' Generate heatmap plot of patient similarity matrix.
#'
#' This function plots a heatmap of a patient similarity matrix.
#' @param simMat - The patient similarity matrix.
#' @param path - The filepath to a directory in which you want to store the .png file.
#' @param diagnoses - A character vector of diagnostic labels associated with the rownames of simMat.
#' @export plot.ptSimilarity
#' @examples
#' plot.ptSimilarity(simMat, path)
plot.ptSimilarity <- function(simMat, path, diagnoses=NULL) {
  if (is.null(diagnoses)) {
    png(sprintf("%s/ptSimilarity.png", path), 3000, 1000)
    heatmap.2(x=simMat,
              dendrogram="both",
              Rowv=TRUE,
              Colv=TRUE,
              cexRow=0.75,cexCol=1, margins=c(12,12),
              trace="none", key=TRUE,
              col=bluered,
              notecol="black")
    dev.off()
  } else {
    d <- diagnoses
    png(sprintf("%s/ptSimilarity.png", path), 3000, 1000)
    heatmap.2(x=simMat,
              dendrogram="both",
              Rowv=TRUE,
              Colv=TRUE,
              ColSideColors = c(brewer.pal(12, "Set3"), brewer.pal(9, "BrBG"))[as.numeric(as.factor(as.character(d)))],
              RowSideColors = c(brewer.pal(12, "Set3"), brewer.pal(9, "BrBG"))[as.numeric(as.factor(as.character(d)))],
              cexRow=0.75,cexCol=1, margins=c(12,12),
              trace="none", key=TRUE,
              col=bluered,
              notecol="black")
    legend("left", legend=unique(sort(as.character(d))), fill=c(brewer.pal(12, "Set3"), brewer.pal(9, "BrBG")), cex=2)
    dev.off()
  }
  return(0)
}
lashmore/MolEndoMatch documentation built on May 5, 2019, 8:02 p.m.