R/dendro_plot.R

Defines functions dendro_plot

Documented in dendro_plot

################################################################################
#' @title Make a clean dendrogram plot
#' @description This function takes a dendrogram and make plot using the
#' \code{\link{ggdendrogram}} function. The returned plot is a ggplot object
#'
#' This function should be only called from internal
#'
#' @param dend a dendrograme, generated by dendrogram_basic function.
#' @param rotate logic value. If true, the output plot will be rotated 90 degree
#' clockwise. Useful to make row wise dendrogram
#' @param x.expand numeric. The x expand value. This value is used to make sure
#' the width of the dendrogram is exactly the same as the heatmap.
#' @keywords internal
dendro_plot = function(dend, rotate = FALSE, x.expand){
    p = ggdendrogram(dend, labels=F, rotate = rotate, theme_dendro=T) +
        scale_y_continuous(expand=c(0,0)) +
        scale_x_continuous(expand = c(x.expand,0)) +
        labs(x="",y="") +
        theme(
            # axis
            axis.text.x = element_blank(),
            axis.text.y = element_blank(),
            axis.title.x = element_blank(),
            axis.title.y = element_blank()
        )
    if(rotate){
        p = p + theme(plot.margin = margin(0,5,0,0))
    }else{
        p = p + theme(plot.margin = margin(5,0,0,0))
    }
}
zhuchcn/zheatmap documentation built on July 18, 2019, 3:14 p.m.