Flexible Heatmaps

library(heatmapFlex)
#> Loading required package: Biobase
#> Loading required package: BiocGenerics
#> Loading required package: generics
#> 
#> Attaching package: 'generics'
#> The following objects are masked from 'package:base':
#> 
#>     as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
#>     setequal, union
#> 
#> Attaching package: 'BiocGenerics'
#> The following objects are masked from 'package:stats':
#> 
#>     IQR, mad, sd, var, xtabs
#> The following objects are masked from 'package:base':
#> 
#>     Filter, Find, Map, Position, Reduce, anyDuplicated, aperm, append,
#>     as.data.frame, basename, cbind, colnames, dirname, do.call,
#>     duplicated, eval, evalq, get, grep, grepl, is.unsorted, lapply,
#>     mapply, match, mget, order, paste, pmax, pmax.int, pmin, pmin.int,
#>     rank, rbind, rownames, sapply, saveRDS, table, tapply, unique,
#>     unsplit, which.max, which.min
#> Welcome to Bioconductor
#> 
#>     Vignettes contain introductory material; view with
#>     'browseVignettes()'. To cite Bioconductor, see
#>     'citation("Biobase")', and for packages 'citation("pkgname")'.
#> Loading required package: Heatplus

License

GPL-3

Description

The package has a number of tools supporting more flexible heatmaps. The graphics is grid-like using the old graphics system. The main function is , which is a wrapper around the various functions constructing individual parts of the heatmap, like sidebars, picket plots, legends etc. The function supports zooming and splitting, i.e., having (unlimited) small heatmaps underneath each other in one plot deriving from the same data set, e.g., clustered and ordered by a supervised clustering method.

Installation

CRAN

install.packages("heatmapFlex")

Latest development version

install.packages("devtools")  
devtools::install_github("vfey/heatmapFlex")

Usage

A simple example

Generate a random 10x10 matrix and plot it using default values (which admittedly is not pretty):

mat <- matrix(rnorm(100), nrow = 10)
heatmap.n2(mat)

A split heatmap

Generate a random 10x10 matrix with two distinct sets, order it using default clustering methods, split it into each two groups along both rows and columns and adjust colour palette and dendrogram dimensions:

mat <- matrix(c(rnorm(50, mean = 1), rnorm(50, mean = -1)), nrow = 10)
heatmap.n2(mat, col = "BuWtRd", rowMembers=rep(1:2, each=5),
           colMembers=rep(1:2, each=5),
           labRow=paste0("gene-", 1:10),
           labCol=paste0(c("A", "B"), rep(1:5, 2)), r.cex=0.8,
           dendroheight = lcm(2.2), dendrowidth = lcm(2.4))

A zoomed heatmap

The heatmap is drawn as in the previous example but without splitting. After it has been plotted to a screen graphics device and calling it can be zoomed into by clicking two distinct points inside the plot.

mat <- matrix(c(rnorm(50, mean = 1), rnorm(50, mean = -1)), nrow = 10)
dl <- heatmap.n2(mat, col = "BuWtRd", labRow=paste0("gene-", 1:10),
                 labCol=paste0(c("A", "B"), rep(1:5, 2)),
                 r.cex=0.8, dendroheight = lcm(2.2), dendrowidth = lcm(2.4))
zoom_heatmap(dl)
zoomed_example_heatmap
zoomed_example_heatmap

A split heatmap with sidebars and picketplot

Sidebars are defined in a list of data frames where each list slot is one of the four sides of the heatmap, “bottom”, “left”, “top”, “right”, and each column in the data frame represents some statistics or other numerical variable describing the rows or columns of the data matrix. The picketplot takes in a data frame with columns consisting of 0 and 1. The columns describe categories that the samples (rows in the picketdata) belong to, such as sex or a health stage. The categories must be binary, like in this example, and have two rows, ‘female’ and ‘male’, and the rows (=samples) are coded with 1 (=TRUE) and 0 (=FALSE).

mat <- matrix(c(rnorm(50, mean = 1), rnorm(50, mean = -1)), nrow = 10)
pd <- data.frame(female=c(0,0,1,0,1,1,0,1,0,1), male=c(1,1,0,1,0,0,0,0,1,0),
                 row.names = paste0(c("A", "B"), rep(1:5, 2)),
                 undeclared=c(0,0,0,0,0,0,1,0,0,0))
pd
#>    female male undeclared
#> A1      0    1          0
#> B2      0    1          0
#> A3      1    0          0
#> B4      0    1          0
#> A5      1    0          0
#> B1      1    0          0
#> A2      0    0          1
#> B3      1    0          0
#> A4      0    1          0
#> B5      1    0          0
dl <- heatmap.n2(
  mat,
  col = "BuWtRd",
  rowMembers=rep(1:2, each=5),
  colMembers=rep(1:2, each=5),
  labRow=paste0("gene-", 1:10),
  labCol=paste0(c("A", "B"), rep(1:5, 2)),
  r.cex=0.8,
  dendroheight = lcm(2.2),
  dendrowidth = lcm(2.4),
  sidebars = list(left=data.frame(min=apply(mat, 1, min), max=apply(mat, 1, max)),
                  bottom=data.frame(
                    mean=apply(mat, 2, mean, na.rm=TRUE),
                    treat=factor(rep(c("A", "B"), 5)))),
  factorpalettefn = colorRampPalette(c("lightblue", "limegreen")),
  picketdata = pd)