R/plotting.R

Defines functions heatmap savefig

Documented in heatmap savefig

# plotting =============================================

#' Heatmap
#' @param x matrix
#' @param aspect aspect
#' @param xlab label of x axis
#' @param ylab label of y axis
#' @param col colormap
#' @param ylim y limits
#' @param useRaster if TRUE a bitmap raster is used to plot 
#' the image instead of polygons
#' @param ... additional parameters
#' @importFrom graphics axis box par
#' @export
heatmap = function(x,
                   aspect = 'fill',
                   xlab = 'column',
                   ylab = 'row',
                   col = pals::coolwarm(100),
                   ylim = c(nrow(x) + 0.5, 0.5), 
                   useRaster = TRUE, ...) {
    
    if ( isTRUE(useRaster) ) {
        x = flipud(x)
    }
    
    lattice::levelplot(t(x), aspect = aspect, 
                       xlab = xlab, ylab = ylab, 
                       col.regions = col,
                       ylim = ylim, 
                       useRaster = useRaster, ...)
    
}



# figure saving =========================================

#' Wrapper for devEval using Tufte's aspect ratio
#' @param ... parameters for `devEval`
#' @param aspectRatio aspect ratio. 
#' Defaults to the inverse golden ratio
#' @export
savefig = function(..., aspectRatio = 1/golden_ratio()) {
    R.devices::devEval(..., aspectRatio = aspectRatio)
}
unoe/noe documentation built on Nov. 5, 2019, 11:05 a.m.