knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(heatmapFlex)
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 \code{heatmap.n2}, 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.
install.packages("heatmapFlex")
install.packages("devtools") devtools::install_github("vfey/heatmapFlex")
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)
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))
The heatmap is drawn as in the previous example but without splitting. After it has been plotted to a screen graphics device and calling \code{zoom_heatmap} 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)
{width=85%}
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 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)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.