This document explains basic functions of the gapmap
package to draw a gapped cluster heatmap. The plot is generated using the ggplot2
package. Let’s load the library first.
library(gapmap)
We will simulate a simple dataset.
set.seed(1234)
<- rnorm(10, mean=rep(1:5, each=2), sd=0.4)
x <- rnorm(10, mean=rep(c(1,2), each=5), sd=0.4)
y <- data.frame(x=x, y=y, row.names=c(1:10))
dataFrame #calculate distance matrix. default is Euclidean distance
<- dist(dataFrame)
distxy #perform hierarchical clustering. default is complete linkage.
<- hclust(distxy)
hc <- as.dendrogram(hc) dend
To make a gapped cluster heatmap, you need to pass a matrix
object for heatmap, and dendrogram
class objects for drawing dendrograms and ordering.
=c("#333333", "#5C5C5C", "#757575", "#8A8A8A", "#9B9B9B", "#AAAAAA", "#B8B8B8", "#C5C5C5", "#D0D0D0", "#DBDBDB", "#E6E6E6")
grey_scale gapmap(m = as.matrix(distxy), d_row= rev(dend), d_col=dend, col = grey_scale)
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
The default of gapmap
function is in the quantitative mode and uses exponential mapping. First, you can choose either modes: quantitative or threshold.
The following example uses the linear mapping. This mapping generate more gaps, whereas the previous example of exponential mapping emphasize on the large gaps.
gapmap(m = as.matrix(distxy), d_row= rev(dend), d_col=dend, mode = "quantitative", mapping="linear", col = grey_scale)
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
The following example illustrate the difference of two mapping schemes. For the exponential mapping, the scale log base is set to 0.5.
The variation of scale log base settings is illustrated in the following plot. The value of scale is annotated on the plot.
Besides the quantitative mode, there is linear mode to introduce gap by a threshold. In the following example, the dendrograms for rows and columns are cut at the threshold distance of 2 and gaps of the same size are introduced between clusters.
gapmap(m = as.matrix(distxy), d_row= rev(dend), d_col=dend, mode = "threshold", row_threshold = 2, col_threshold = 2, col = grey_scale)
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
In addition, this package works well with our dendrogram sorting package, called dendsort
. For the details on dendsort, please check our paper.
library(dendsort);
gapmap(m = as.matrix(distxy), d_row= rev(dendsort(dend)), d_col=dendsort(dend), mode = "quantitative", col = grey_scale)
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead