Commit id: 2786dac4ddaa97c69cc24e29e121ed1a1624cdf4
Merge branch 'master' of https://github.com/jokergoo/mheatmap
Commit id: a61c101325601aa0d4d3ba81e10c33d4a8b34c63
rows can be split if providing a clustering object
git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ComplexHeatmap@105855 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -1,14 +1,14 @@ |
1 | 1 |
Package: ComplexHeatmap |
2 | 2 |
Type: Package |
3 | 3 |
Title: Making Complex Heatmaps |
4 |
-Version: 1.2.1 |
|
4 |
+Version: 1.2.2 |
|
5 | 5 |
Date: 2015-6-17 |
6 | 6 |
Author: Zuguang Gu |
7 | 7 |
Maintainer: Zuguang Gu <z.gu@dkfz.de> |
8 | 8 |
Depends: R (>= 3.1.0), grid |
9 | 9 |
Imports: methods, circlize (>= 0.2.3), GetoptLong, colorspace, |
10 |
- RColorBrewer |
|
11 |
-Suggests: testthat (>= 0.3), knitr, markdown, cluster, dendextend |
|
10 |
+ RColorBrewer, dendextend (>= 1.0.1) |
|
11 |
+Suggests: testthat (>= 0.3), knitr, markdown, cluster |
|
12 | 12 |
VignetteBuilder: knitr |
13 | 13 |
Description: Complex heatmaps are efficient to visualize associations |
14 | 14 |
between different sources of data sets and reveal potential features. |
... | ... |
@@ -1,3 +1,10 @@ |
1 |
+CHANGES in VERSION 1.2.2 |
|
2 |
+ |
|
3 |
+* rows can be split if `cluster_rows` are a clustering object |
|
4 |
+* `row_order` and `column_order` can be set by dimension names |
|
5 |
+ |
|
6 |
+=========================================== |
|
7 |
+ |
|
1 | 8 |
CHANGES in VERSION 1.2.1 |
2 | 9 |
|
3 | 10 |
* adjust orders of row slices |
... | ... |
@@ -170,7 +170,8 @@ Heatmap = setClass("Heatmap", |
170 | 170 |
# -bottom_annotation_height total height of the column annotations on the bottom. |
171 | 171 |
# -km do k-means clustering on rows. If the value is larger than 1, the heatmap will be split by rows according to the k-means clustering. |
172 | 172 |
# For each row-clusters, hierarchical clustering is still applied with parameters above. |
173 |
-# -split a vector or a data frame by which the rows are split. |
|
173 |
+# -split a vector or a data frame by which the rows are split. But if ``cluster_rows`` is a clustering object, ``split`` can be a single number |
|
174 |
+# indicating rows are to be split according to the split on the tree. |
|
174 | 175 |
# -gap gap between row-slices if the heatmap is split by rows, should be `grid::unit` object. |
175 | 176 |
# -combined_name_fun if the heatmap is split by rows, how to make a combined row title for each slice? |
176 | 177 |
# The input parameter for this function is a vector which contains level names under each column in ``split``. |
... | ... |
@@ -267,9 +268,13 @@ Heatmap = function(matrix, col, name, na_col = "grey", rect_gp = gpar(col = NA), |
267 | 268 |
.Object@matrix_param$km = km |
268 | 269 |
.Object@matrix_param$gap = gap |
269 | 270 |
if(!is.null(split)) { |
270 |
- if(!is.data.frame(split)) split = data.frame(split) |
|
271 |
- if(nrow(split) != nrow(matrix)) { |
|
272 |
- stop("Length or number of rows of `split` should be same as rows in `matrix`.") |
|
271 |
+ if(inherits(cluster_rows, c("dendrogram", "hclust"))) { |
|
272 |
+ .Object@matrix_param$split = split |
|
273 |
+ } else { |
|
274 |
+ if(!is.data.frame(split)) split = data.frame(split) |
|
275 |
+ if(nrow(split) != nrow(matrix)) { |
|
276 |
+ stop("Length or number of rows of `split` should be same as rows in `matrix`.") |
|
277 |
+ } |
|
273 | 278 |
} |
274 | 279 |
} |
275 | 280 |
.Object@matrix_param$split = split |
... | ... |
@@ -382,6 +387,9 @@ Heatmap = function(matrix, col, name, na_col = "grey", rect_gp = gpar(col = NA), |
382 | 387 |
if(is.null(row_order)) { |
383 | 388 |
.Object@row_order = seq_len(nrow(matrix)) |
384 | 389 |
} else { |
390 |
+ if(is.character(row_order)) { |
|
391 |
+ row_order = structure(seq_len(nrow(matrix)), names = rownames(matrix))[row_order] |
|
392 |
+ } |
|
385 | 393 |
.Object@row_order = row_order |
386 | 394 |
} |
387 | 395 |
|
... | ... |
@@ -411,6 +419,9 @@ Heatmap = function(matrix, col, name, na_col = "grey", rect_gp = gpar(col = NA), |
411 | 419 |
if(is.null(column_order)) { |
412 | 420 |
.Object@column_order = seq_len(ncol(matrix)) |
413 | 421 |
} else { |
422 |
+ if(is.character(column_order)) { |
|
423 |
+ column_order = structure(seq_len(ncol(matrix)), names = colnames(matrix))[column_order] |
|
424 |
+ } |
|
414 | 425 |
.Object@column_order = column_order |
415 | 426 |
} |
416 | 427 |
|
... | ... |
@@ -555,11 +566,26 @@ setMethod(f = "make_row_cluster", |
555 | 566 |
if(km > 1) { |
556 | 567 |
stop("You can not make k-means clustering since you have already specified a clustering object.") |
557 | 568 |
} |
558 |
- if(!is.null(split)) { |
|
559 |
- stop("You can not split by rows since you have already specified a clustering object.") |
|
569 |
+ if(is.null(split)) { |
|
570 |
+ object@row_hclust_list = list(object@row_hclust_param$obj) |
|
571 |
+ object@row_order_list = list(get_hclust_order(object@row_hclust_param$obj)) |
|
572 |
+ } else { |
|
573 |
+ if(length(split) > 1 || !is.numeric(split)) { |
|
574 |
+ stop("Since you specified a clustering object, you can only split rows by providing a number (number of row slices.") |
|
575 |
+ } |
|
576 |
+ if(split < 2) { |
|
577 |
+ stop("Here `split` should be equal or larger than 2.") |
|
578 |
+ } |
|
579 |
+ if(inherits(object@row_hclust_param$obj, "hclust")) { |
|
580 |
+ object@row_hclust_param$obj = as.dendrogram(object@row_hclust_param$obj) |
|
581 |
+ } |
|
582 |
+ object@row_hclust_list = cut_dendrogram(object@row_hclust_param$obj, split) |
|
583 |
+ sth = tapply(order.dendrogram(object@row_hclust_param$obj), |
|
584 |
+ rep(seq_along(object@row_hclust_list), times = sapply(object@row_hclust_list, nobs)), |
|
585 |
+ function(x) x) |
|
586 |
+ attributes(sth) = NULL |
|
587 |
+ object@row_order_list = sth |
|
560 | 588 |
} |
561 |
- object@row_hclust_list = list(object@row_hclust_param$obj) |
|
562 |
- object@row_order_list = list(get_hclust_order(object@row_hclust_param$obj)) |
|
563 | 589 |
return(object) |
564 | 590 |
} |
565 | 591 |
|
... | ... |
@@ -322,6 +322,14 @@ get_hclust_order = function(x) { |
322 | 322 |
dendrogram = order.dendrogram(x)) |
323 | 323 |
} |
324 | 324 |
|
325 |
+# can only cut dendrogram for which branches at every node are two |
|
326 |
+cut_dendrogram = function(dend, k) { |
|
327 |
+ h = sort(get_branches_heights(dend), decreasing = TRUE) |
|
328 |
+ height = (h[k-1] + h[k])/2 |
|
329 |
+ trees = cut(dend, h = height) |
|
330 |
+ trees$lower |
|
331 |
+} |
|
332 |
+ |
|
325 | 333 |
recycle_gp = function(gp, n = 1) { |
326 | 334 |
for(i in seq_along(gp)) { |
327 | 335 |
x = gp[[i]] |
... | ... |
@@ -34,8 +34,6 @@ Zuguang Gu <z.gu@dkfz.de> |
34 | 34 |
|
35 | 35 |
} |
36 | 36 |
\examples{ |
37 |
- |
|
38 |
- |
|
39 | 37 |
# discrete color mapping for characters |
40 | 38 |
cm = ColorMapping(name = "test", |
41 | 39 |
colors = c("blue", "white", "red"), |
... | ... |
@@ -52,6 +50,4 @@ cm |
52 | 50 |
require(circlize) |
53 | 51 |
cm = ColorMapping(name = "test", |
54 | 52 |
col_fun = colorRamp2(c(0, 0.5, 1), c("blue", "white", "red"))) |
55 |
-cm |
|
56 |
- |
|
57 |
-} |
|
53 |
+cm} |
... | ... |
@@ -80,7 +80,7 @@ Heatmap(matrix, col, name, na_col = "grey", rect_gp = gpar(col = NA), |
80 | 80 |
\item{bottom_annotation}{a \code{\link{HeatmapAnnotation}} object.} |
81 | 81 |
\item{bottom_annotation_height}{total height of the column annotations on the bottom.} |
82 | 82 |
\item{km}{do k-means clustering on rows. If the value is larger than 1, the heatmap will be split by rows according to the k-means clustering.For each row-clusters, hierarchical clustering is still applied with parameters above.} |
83 |
- \item{split}{a vector or a data frame by which the rows are split.} |
|
83 |
+ \item{split}{a vector or a data frame by which the rows are split. But if \code{cluster_rows} is a clustering object, \code{split} can be a single numberindicating rows are to be split according to the split on the tree.} |
|
84 | 84 |
\item{gap}{gap between row-slices if the heatmap is split by rows, should be \code{\link[grid]{unit}} object.} |
85 | 85 |
\item{combined_name_fun}{if the heatmap is split by rows, how to make a combined row title for each slice?The input parameter for this function is a vector which contains level names under each column in \code{split}.} |
86 | 86 |
\item{width}{the width of the single heatmap, should be a fixed \code{\link[grid]{unit}} object. It is used for the layout when the heatmapis appended to a list of heatmaps.} |
... | ... |
@@ -111,8 +111,6 @@ Zuguang Gu <z.gu@dkfz.de> |
111 | 111 |
|
112 | 112 |
} |
113 | 113 |
\examples{ |
114 |
- |
|
115 |
- |
|
116 | 114 |
mat = matrix(rnorm(80, 2), 8, 10) |
117 | 115 |
mat = rbind(mat, matrix(rnorm(40, -2), 4, 10)) |
118 | 116 |
rownames(mat) = letters[1:12] |
... | ... |
@@ -183,6 +181,4 @@ Heatmap(mat, rect_gp = gpar(col = "white"), |
183 | 181 |
grid.text(mat[i, j], x = x, y = y) |
184 | 182 |
}, |
185 | 183 |
cluster_rows = FALSE, cluster_columns = FALSE, row_names_side = "left", |
186 |
- column_names_side = "top") |
|
187 |
- |
|
188 |
-} |
|
184 |
+ column_names_side = "top")} |
... | ... |
@@ -46,8 +46,6 @@ Zuguang Gu <z.gu@dkfz.de> |
46 | 46 |
|
47 | 47 |
} |
48 | 48 |
\examples{ |
49 |
- |
|
50 |
- |
|
51 | 49 |
df = data.frame(type = c("a", "a", "a", "b", "b", "b")) |
52 | 50 |
ha = HeatmapAnnotation(df = df) |
53 | 51 |
|
... | ... |
@@ -61,6 +59,4 @@ ha = HeatmapAnnotation(points = anno_points(1:6)) |
61 | 59 |
ha = HeatmapAnnotation(histogram = anno_points(1:6)) |
62 | 60 |
|
63 | 61 |
mat = matrix(rnorm(36), 6) |
64 |
-ha = HeatmapAnnotation(boxplot = anno_boxplot(mat)) |
|
65 |
- |
|
66 |
-} |
|
62 |
+ha = HeatmapAnnotation(boxplot = anno_boxplot(mat))} |
... | ... |
@@ -68,8 +68,6 @@ Zuguang Gu <z.gu@dkfz.de> |
68 | 68 |
|
69 | 69 |
} |
70 | 70 |
\examples{ |
71 |
- |
|
72 |
- |
|
73 | 71 |
mat = matrix(rnorm(80, 2), 8, 10) |
74 | 72 |
mat = rbind(mat, matrix(rnorm(40, -2), 4, 10)) |
75 | 73 |
rownames(mat) = letters[1:12] |
... | ... |
@@ -85,6 +83,4 @@ ht + ht_list |
85 | 83 |
ha = HeatmapAnnotation(points = anno_points(1:12, which = "row"), |
86 | 84 |
which = "row") |
87 | 85 |
ht + ha |
88 |
-ht_list + ha |
|
89 |
- |
|
90 |
-} |
|
86 |
+ht_list + ha} |
... | ... |
@@ -48,8 +48,6 @@ Zuguang Gu <z.gu@dkfz.de> |
48 | 48 |
|
49 | 49 |
} |
50 | 50 |
\examples{ |
51 |
- |
|
52 |
- |
|
53 | 51 |
# discrete character |
54 | 52 |
SingleAnnotation(name = "test", value = c("a", "a", "a", "b", "b", "b")) |
55 | 53 |
SingleAnnotation(name = "test", value = c("a", "a", "a", "b", "b", "b"), |
... | ... |
@@ -65,6 +63,4 @@ SingleAnnotation(value = 1:10) |
65 | 63 |
SingleAnnotation(value = 1:10, col = colorRamp2(c(1, 10), c("blue", "red"))) |
66 | 64 |
|
67 | 65 |
# self-defined graphic function |
68 |
-SingleAnnotation(fun = anno_points(1:10)) |
|
69 |
- |
|
70 |
-} |
|
66 |
+SingleAnnotation(fun = anno_points(1:10))} |
... | ... |
@@ -31,8 +31,6 @@ Zuguang Gu <z.gu@dkfz.de> |
31 | 31 |
|
32 | 32 |
} |
33 | 33 |
\examples{ |
34 |
- |
|
35 |
- |
|
36 | 34 |
mat = matrix(rnorm(80, 2), 8, 10) |
37 | 35 |
mat = rbind(mat, matrix(rnorm(40, -2), 4, 10)) |
38 | 36 |
rownames(mat) = letters[1:12] |
... | ... |
@@ -50,6 +48,4 @@ ha = HeatmapAnnotation(points = anno_points(1:12, which = "row"), |
50 | 48 |
ht + ha |
51 | 49 |
ht_list + ha |
52 | 50 |
|
53 |
-ha + ha + ht |
|
54 |
- |
|
55 |
-} |
|
51 |
+ha + ha + ht} |
... | ... |
@@ -28,8 +28,6 @@ Zuguang Gu <z.gu@dkfz.de> |
28 | 28 |
|
29 | 29 |
} |
30 | 30 |
\examples{ |
31 |
- |
|
32 |
- |
|
33 | 31 |
mat = matrix(rnorm(80, 2), 8, 10) |
34 | 32 |
mat = rbind(mat, matrix(rnorm(40, -2), 4, 10)) |
35 | 33 |
rownames(mat) = letters[1:12] |
... | ... |
@@ -40,6 +38,4 @@ add_heatmap(ht, ht) |
40 | 38 |
|
41 | 39 |
ha = HeatmapAnnotation(points = anno_points(1:12, which = "row"), |
42 | 40 |
which = "row") |
43 |
-add_heatmap(ht, ha) |
|
44 |
- |
|
45 |
-} |
|
41 |
+add_heatmap(ht, ha)} |
... | ... |
@@ -28,8 +28,6 @@ Zuguang Gu <z.gu@dkfz.de> |
28 | 28 |
|
29 | 29 |
} |
30 | 30 |
\examples{ |
31 |
- |
|
32 |
- |
|
33 | 31 |
mat = matrix(rnorm(80, 2), 8, 10) |
34 | 32 |
mat = rbind(mat, matrix(rnorm(40, -2), 4, 10)) |
35 | 33 |
rownames(mat) = letters[1:12] |
... | ... |
@@ -39,6 +37,4 @@ ht = Heatmap(mat) |
39 | 37 |
|
40 | 38 |
ha = HeatmapAnnotation(points = anno_points(1:12, which = "row"), |
41 | 39 |
which = "row") |
42 |
-add_heatmap(ha, ht) |
|
43 |
- |
|
44 |
-} |
|
40 |
+add_heatmap(ha, ht)} |
... | ... |
@@ -28,8 +28,6 @@ Zuguang Gu <z.gu@dkfz.de> |
28 | 28 |
|
29 | 29 |
} |
30 | 30 |
\examples{ |
31 |
- |
|
32 |
- |
|
33 | 31 |
mat = matrix(rnorm(80, 2), 8, 10) |
34 | 32 |
mat = rbind(mat, matrix(rnorm(40, -2), 4, 10)) |
35 | 33 |
rownames(mat) = letters[1:12] |
... | ... |
@@ -41,6 +39,4 @@ add_heatmap(ht_list, ht) |
41 | 39 |
|
42 | 40 |
ha = HeatmapAnnotation(points = anno_points(1:12, which = "row"), |
43 | 41 |
which = "row") |
44 |
-add_heatmap(ht_list, ha) |
|
45 |
- |
|
46 |
-} |
|
42 |
+add_heatmap(ht_list, ha)} |
... | ... |
@@ -32,8 +32,6 @@ Zuguang Gu <z.gu@dkfz.de> |
32 | 32 |
|
33 | 33 |
} |
34 | 34 |
\examples{ |
35 |
- |
|
36 |
- |
|
37 | 35 |
mat = matrix(rnorm(32), nrow = 4) |
38 | 36 |
f = anno_boxplot(mat) |
39 | 37 |
grid.newpage(); f(1:8) |
... | ... |
@@ -43,6 +41,4 @@ grid.newpage(); f(1:4) |
43 | 41 |
|
44 | 42 |
lt = lapply(1:4, function(i) rnorm(8)) |
45 | 43 |
f = anno_boxplot(lt) |
46 |
-grid.newpage(); f(1:4) |
|
47 |
- |
|
48 |
-} |
|
44 |
+grid.newpage(); f(1:4)} |
... | ... |
@@ -28,8 +28,6 @@ Zuguang Gu <z.gu@dkfz.de> |
28 | 28 |
|
29 | 29 |
} |
30 | 30 |
\examples{ |
31 |
- |
|
32 |
- |
|
33 | 31 |
mat = matrix(rnorm(32), nrow = 4) |
34 | 32 |
f = anno_density(mat) |
35 | 33 |
grid.newpage(); f(1:8) |
... | ... |
@@ -39,6 +37,4 @@ grid.newpage(); f(1:4) |
39 | 37 |
|
40 | 38 |
lt = lapply(1:4, function(i) rnorm(8)) |
41 | 39 |
f = anno_density(lt, type = "heatmap") |
42 |
-grid.newpage(); f(1:4) |
|
43 |
- |
|
44 |
-} |
|
40 |
+grid.newpage(); f(1:4)} |
... | ... |
@@ -26,8 +26,6 @@ Zuguang Gu <z.gu@dkfz.de> |
26 | 26 |
|
27 | 27 |
} |
28 | 28 |
\examples{ |
29 |
- |
|
30 |
- |
|
31 | 29 |
mat = matrix(rnorm(32), nrow = 4) |
32 | 30 |
f = anno_histogram(mat) |
33 | 31 |
grid.newpage(); f(1:8) |
... | ... |
@@ -37,6 +35,4 @@ grid.newpage(); f(1:4) |
37 | 35 |
|
38 | 36 |
lt = lapply(1:4, function(i) rnorm(8)) |
39 | 37 |
f = anno_histogram(lt) |
40 |
-grid.newpage(); f(1:4) |
|
41 |
- |
|
42 |
-} |
|
38 |
+grid.newpage(); f(1:4)} |
... | ... |
@@ -29,13 +29,9 @@ Zuguang Gu <z.gu@dkfz.de> |
29 | 29 |
|
30 | 30 |
} |
31 | 31 |
\examples{ |
32 |
- |
|
33 |
- |
|
34 | 32 |
mat = matrix(rnorm(100), 10) |
35 | 33 |
colnames(mat) = letters[1:10] |
36 | 34 |
rownames(mat) = LETTERS[1:10] |
37 | 35 |
long_cn = do.call("paste0", rep(list(colnames(mat)), 4)) # just to construct long text |
38 | 36 |
ha_rot_cn = HeatmapAnnotation(text = anno_text(long_cn, rot = 45, offset = unit(5, "mm"))) |
39 |
-Heatmap(mat, name = "foo", top_annotation = ha_rot_cn, top_annotation_height = unit(1.2, "cm")) |
|
40 |
- |
|
41 |
-} |
|
37 |
+Heatmap(mat, name = "foo", top_annotation = ha_rot_cn, top_annotation_height = unit(1.2, "cm"))} |
... | ... |
@@ -38,8 +38,6 @@ Zuguang Gu <z.gu@dkfz.de> |
38 | 38 |
|
39 | 39 |
} |
40 | 40 |
\examples{ |
41 |
- |
|
42 |
- |
|
43 | 41 |
# discrete color mapping for characters |
44 | 42 |
cm = ColorMapping(name = "test", |
45 | 43 |
colors = c("blue", "white", "red"), |
... | ... |
@@ -59,6 +57,4 @@ require(circlize) |
59 | 57 |
cm = ColorMapping(name = "test", |
60 | 58 |
col_fun = colorRamp2(c(0, 0.5, 1), c("blue", "white", "red"))) |
61 | 59 |
grid.newpage() |
62 |
-color_mapping_legend(cm, legend_title_gp = gpar(fontsize = 16)) |
|
63 |
- |
|
64 |
-} |
|
60 |
+color_mapping_legend(cm, legend_title_gp = gpar(fontsize = 16))} |
... | ... |
@@ -20,8 +20,6 @@ This function is only for internal use. |
20 | 20 |
|
21 | 21 |
} |
22 | 22 |
\section{Detials}{ |
23 |
- |
|
24 |
- |
|
25 | 23 |
This function is only for internal use.} |
26 | 24 |
\value{ |
27 | 25 |
A \code{\link[grid]{unit}} object. |
... | ... |
@@ -32,8 +30,4 @@ Zuguang Gu <z.gu@dkfz.de> |
32 | 30 |
|
33 | 31 |
} |
34 | 32 |
\examples{ |
35 |
- |
|
36 |
- |
|
37 |
-# no example for this internal method |
|
38 |
- |
|
39 |
-} |
|
33 |
+# no example for this internal method} |
... | ... |
@@ -30,8 +30,6 @@ Zuguang Gu <z.gu@dkfz.de> |
30 | 30 |
|
31 | 31 |
} |
32 | 32 |
\examples{ |
33 |
- |
|
34 |
- |
|
35 | 33 |
mat = matrix(rnorm(40), nr = 4, ncol = 10) |
36 | 34 |
rownames(mat) = letters[1:4] |
37 | 35 |
colnames(mat) = letters[1:10] |
... | ... |
@@ -41,6 +39,4 @@ d2 = dist2(mat, pairwise_fun = function(x, y) 1 - cor(x, y)) |
41 | 39 |
d2 = dist2(mat, pairwise_fun = function(x, y) { |
42 | 40 |
l = is.na(x) & is.na(y) |
43 | 41 |
sqrt(sum((x[l] - y[l])^2)) |
44 |
-}) |
|
45 |
- |
|
46 |
-} |
|
42 |
+})} |
... | ... |
@@ -31,14 +31,10 @@ Zuguang Gu <z.gu@dkfz.de> |
31 | 31 |
|
32 | 32 |
} |
33 | 33 |
\examples{ |
34 |
- |
|
35 |
- |
|
36 | 34 |
mat = matrix(rnorm(80, 2), 8, 10) |
37 | 35 |
mat = rbind(mat, matrix(rnorm(40, -2), 4, 10)) |
38 | 36 |
rownames(mat) = letters[1:12] |
39 | 37 |
colnames(mat) = letters[1:10] |
40 | 38 |
|
41 | 39 |
ht = Heatmap(mat) |
42 |
-draw(ht, heatmap_legend_side = "left") |
|
43 |
- |
|
44 |
-} |
|
40 |
+draw(ht, heatmap_legend_side = "left")} |
... | ... |
@@ -30,8 +30,6 @@ Zuguang Gu <z.gu@dkfz.de> |
30 | 30 |
|
31 | 31 |
} |
32 | 32 |
\examples{ |
33 |
- |
|
34 |
- |
|
35 | 33 |
df = data.frame(type = c("a", "a", "a", "b", "b", "b")) |
36 | 34 |
ha = HeatmapAnnotation(df = df) |
37 | 35 |
grid.newpage(); draw(ha, 1:6) |
... | ... |
@@ -52,6 +50,4 @@ grid.newpage(); draw(ha, 1:6) |
52 | 50 |
|
53 | 51 |
mat = matrix(rnorm(36), 6) |
54 | 52 |
ha = HeatmapAnnotation(boxplot = anno_boxplot(mat)) |
55 |
-grid.newpage(); draw(ha, 1:6) |
|
56 |
- |
|
57 |
-} |
|
53 |
+grid.newpage(); draw(ha, 1:6)} |
... | ... |
@@ -33,8 +33,6 @@ Zuguang Gu <z.gu@dkfz.de> |
33 | 33 |
|
34 | 34 |
} |
35 | 35 |
\examples{ |
36 |
- |
|
37 |
- |
|
38 | 36 |
mat = matrix(rnorm(80, 2), 8, 10) |
39 | 37 |
mat = rbind(mat, matrix(rnorm(40, -2), 4, 10)) |
40 | 38 |
rownames(mat) = letters[1:12] |
... | ... |
@@ -44,6 +42,4 @@ ht = Heatmap(mat) |
44 | 42 |
ht_list = ht + ht |
45 | 43 |
draw(ht_list) |
46 | 44 |
draw(ht_list, row_title = "row title", column_title = "column title", |
47 |
- heatmap_legend_side = "top") |
|
48 |
- |
|
49 |
-} |
|
45 |
+ heatmap_legend_side = "top")} |
... | ... |
@@ -31,8 +31,6 @@ Zuguang Gu <z.gu@dkfz.de> |
31 | 31 |
|
32 | 32 |
} |
33 | 33 |
\examples{ |
34 |
- |
|
35 |
- |
|
36 | 34 |
anno = SingleAnnotation(name = "test", value = c("a", "a", "a", "b", "b", "b")) |
37 | 35 |
grid.newpage(); draw(anno, 1:5) |
38 | 36 |
grid.newpage(); draw(anno, c(1, 4, 3, 5, 2)) |
... | ... |
@@ -54,6 +52,4 @@ anno = SingleAnnotation(value = 1:10, col = colorRamp2(c(1, 10), c("blue", "red" |
54 | 52 |
grid.newpage(); draw(anno, 1:10) |
55 | 53 |
|
56 | 54 |
anno = SingleAnnotation(fun = anno_points(1:10)) |
57 |
-grid.newpage(); draw(anno, 1:10) |
|
58 |
- |
|
59 |
-} |
|
55 |
+grid.newpage(); draw(anno, 1:10)} |
... | ... |
@@ -34,8 +34,6 @@ Zuguang Gu <z.gu@dkfz.de> |
34 | 34 |
|
35 | 35 |
} |
36 | 36 |
\examples{ |
37 |
- |
|
38 |
- |
|
39 | 37 |
hc = hclust(dist(USArrests[1:5, ])) |
40 | 38 |
dend = as.dendrogram(hc) |
41 | 39 |
|
... | ... |
@@ -47,6 +45,4 @@ grid.dendrogram(dend, facing = "top", layout.pos.row = 1, layout.pos.col = 2) |
47 | 45 |
grid.dendrogram(dend, facing = "top", order = "reverse", layout.pos.row = 2, |
48 | 46 |
layout.pos.col = 1) |
49 | 47 |
grid.dendrogram(dend, facing = "left", layout.pos.row = 2, layout.pos.col = 2) |
50 |
-upViewport() |
|
51 |
- |
|
52 |
-} |
|
48 |
+upViewport()} |
... | ... |
@@ -29,8 +29,6 @@ Zuguang Gu <z.gu@dkfz.de> |
29 | 29 |
|
30 | 30 |
} |
31 | 31 |
\examples{ |
32 |
- |
|
33 |
- |
|
34 | 32 |
# discrete color mapping for characters |
35 | 33 |
cm = ColorMapping(name = "test", |
36 | 34 |
colors = c("blue", "white", "red"), |
... | ... |
@@ -51,6 +49,4 @@ require(circlize) |
51 | 49 |
cm = ColorMapping(name = "test", |
52 | 50 |
col_fun = colorRamp2(c(0, 0.5, 1), c("blue", "white", "red"))) |
53 | 51 |
map_to_colors(cm, 0.2) |
54 |
-map_to_colors(cm, seq(0.2, 0.8, by = 0.1)) |
|
55 |
- |
|
56 |
-} |
|
52 |
+map_to_colors(cm, seq(0.2, 0.8, by = 0.1))} |
... | ... |
@@ -46,8 +46,6 @@ Zuguang Gu <z.gu@dkfz.de> |
46 | 46 |
|
47 | 47 |
} |
48 | 48 |
\examples{ |
49 |
- |
|
50 |
- |
|
51 | 49 |
df = data.frame(matrix(rnorm(40), nrow = 10, dimnames = list(letters[1:10], letters[1:4])), |
52 | 50 |
large = runif(10)*100, |
53 | 51 |
t1 = sample(letters[1:3], 10, replace = TRUE), |
... | ... |
@@ -55,6 +53,4 @@ df = data.frame(matrix(rnorm(40), nrow = 10, dimnames = list(letters[1:10], lett |
55 | 53 |
t2 = sample(LETTERS[1:3], 10, replace = TRUE)) |
56 | 54 |
plotDataFrame(df) |
57 | 55 |
plotDataFrame(df, group = list(1:4, 5, 6, 7:12, 13), group_names = c("mat1", "large", "t1", "mat2", "t2"), |
58 |
- main_heatmap = 4, km = 2, column_title = "column title", row_title = "row title") |
|
59 |
- |
|
60 |
-} |
|
56 |
+ main_heatmap = 4, km = 2, column_title = "column title", row_title = "row title")} |
... | ... |
@@ -28,8 +28,6 @@ Zuguang Gu <z.gu@dkfz.de> |
28 | 28 |
|
29 | 29 |
} |
30 | 30 |
\examples{ |
31 |
- |
|
32 |
- |
|
33 | 31 |
mat = matrix(rnorm(80, 2), 8, 10) |
34 | 32 |
mat = rbind(mat, matrix(rnorm(40, -2), 4, 10)) |
35 | 33 |
rownames(mat) = letters[1:12] |
... | ... |
@@ -37,6 +35,4 @@ colnames(mat) = letters[1:10] |
37 | 35 |
|
38 | 36 |
ht = Heatmap(mat) |
39 | 37 |
ht |
40 |
-draw(ht, heatmap_legend_side = "left") |
|
41 |
- |
|
42 |
-} |
|
38 |
+draw(ht, heatmap_legend_side = "left")} |
... | ... |
@@ -272,7 +272,7 @@ Heatmap(mat, name = "foo", cluster_rows = function(m) hclust(dist(m)), |
272 | 272 |
Clustering can help to adjust order in rows and in columns. But you can still set the order manually by `row_order` |
273 | 273 |
and `column_order`. This is convenient if you want to adjust the order of columns when you have many column annotations or |
274 | 274 |
adjust the order of rows if you have many parallel heatmaps plotted together. Note you need to turn off clustering |
275 |
-if you want to set order manually. |
|
275 |
+if you want to set order manually. `row_order` and `column_order` can also be set according to matrix row names and column names. |
|
276 | 276 |
|
277 | 277 |
```{r manual_order} |
278 | 278 |
Heatmap(mat, name = "foo", cluster_rows = FALSE, cluster_columns = FALSE, |
... | ... |
@@ -347,6 +347,14 @@ Character matrix can only be split by `split` argument. |
347 | 347 |
Heatmap(discrete_mat, name = "foo", split = rep(letters[1:2], each = 5)) |
348 | 348 |
``` |
349 | 349 |
|
350 |
+Users may alreay have a dendrogram for rows which were adjusted by some other methods |
|
351 |
+and they want to split rows by splitting the dendrogram into k sub trees. In this case, |
|
352 |
+`split` can be specified as a number: |
|
353 |
+ |
|
354 |
+```{r split_dendrogram} |
|
355 |
+Heatmap(mat, name = "foo", cluster_rows = dend, split = 2) |
|
356 |
+``` |
|
357 |
+ |
|
350 | 358 |
### Self define the heatmap body |
351 | 359 |
|
352 | 360 |
`rect_gp` argument provides basic graphic settings for the heatmap body (`fill` parameter is disabled). |