Browse code

resove conflict

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ComplexHeatmap@120116 bc3139a8-67e5-0310-9ffc-ced21a209358

Zuguang Gu authored on 14/08/2016 09:20:57
Showing28 changed files

... ...
@@ -1,15 +1,15 @@
1 1
 Package: ComplexHeatmap
2 2
 Type: Package
3 3
 Title: Making Complex Heatmaps
4
-Version: 1.11.4
5
-Date: 2016-6-7
4
+Version: 1.11.6
5
+Date: 2016-8-14
6 6
 Author: Zuguang Gu
7 7
 Maintainer: Zuguang Gu <z.gu@dkfz.de>
8 8
 Depends: R (>= 3.1.2), grid, graphics, stats, grDevices
9 9
 Imports: methods, circlize (>= 0.3.4), GetoptLong, colorspace,
10 10
     RColorBrewer, dendextend (>= 1.0.1), GlobalOptions (>= 0.0.10)
11 11
 Suggests: testthat (>= 0.3), knitr, markdown, cluster, MASS, pvclust, 
12
-    dendsort, HilbertCurve, Cairo, png, jpeg, tiff
12
+    dendsort, HilbertCurve, Cairo, png, jpeg, tiff, fastcluster
13 13
 VignetteBuilder: knitr
14 14
 Description: Complex heatmaps are efficient to visualize associations 
15 15
     between different sources of data sets and reveal potential structures. 
... ...
@@ -18,6 +18,6 @@ Description: Complex heatmaps are efficient to visualize associations
18 18
 biocViews: Software, Visualization, Sequencing
19 19
 URL: https://github.com/jokergoo/ComplexHeatmap
20 20
 License: GPL (>= 2)
21
-Packaged: 2016-6-7 00:00:00 UTC; Administrator
21
+Packaged: 2016-8-14 00:00:00 UTC; Administrator
22 22
 Repository: Bioconductor
23
-Date/Publication: 2016-6-7 00:00:00
23
+Date/Publication: 2016-8-14 00:00:00
... ...
@@ -1,100 +1,97 @@
1
-export(column_anno_histogram)
2
-export(anno_boxplot)
3
-exportMethods(column_order)
1
+export('+.AdditiveUnit')
2
+export(AdditiveUnit)
4 3
 export(ColorMapping)
4
+export(Heatmap)
5 5
 export(HeatmapAnnotation)
6
+export(HeatmapList)
7
+export(Legend)
8
+export(SingleAnnotation)
9
+export(anno_barplot)
10
+export(anno_boxplot)
11
+export(anno_density)
12
+export(anno_histogram)
13
+export(anno_link)
14
+export(anno_oncoprint_barplot)
15
+export(anno_points)
16
+export(anno_text)
17
+export(columnAnnotation)
18
+export(column_anno_barplot)
6 19
 export(column_anno_boxplot)
7
-export(selectArea)
8
-export(row_anno_barplot)
9
-export(Heatmap)
10
-export(row_anno_points)
20
+export(column_anno_density)
21
+export(column_anno_histogram)
22
+export(column_anno_link)
23
+export(column_anno_points)
11 24
 export(column_anno_text)
12
-export(decorate_row_dend)
13
-export(decorate_column_dend)
14
-exportMethods(draw)
15
-export(unify_mat_list)
16
-exportMethods(draw_heatmap_body)
17
-exportMethods(color_mapping_legend)
18
-exportMethods(prepare)
19 25
 export(decorate_annotation)
20
-exportMethods(map_to_colors)
26
+export(decorate_column_dend)
27
+export(decorate_column_names)
28
+export(decorate_column_title)
29
+export(decorate_dend)
21 30
 export(decorate_dimnames)
22
-export(column_anno_points)
23
-exportMethods(component_height)
24
-export(row_anno_text)
25
-exportClasses(SingleAnnotation)
26
-export(SingleAnnotation)
27
-export(oncoPrint)
28
-exportClasses(AdditiveUnit)
29
-export(AdditiveUnit)
30
-export(max_text_height)
31
+export(decorate_heatmap_body)
32
+export(decorate_row_dend)
33
+export(decorate_row_names)
34
+export(decorate_row_title)
35
+export(decorate_title)
36
+export(densityHeatmap)
37
+export(dist2)
31 38
 export(enhanced_basicplot)
32
-exportMethods(annotation_legend_size)
33
-exportMethods(row_order)
34
-export(Legend)
35
-export(AdditiveUnit)
36
-exportMethods(draw_heatmap_list)
37
-export(row_anno_density)
39
+export(grid.dendrogram)
40
+export(ht_global_opt)
38 41
 export(is_abs_unit)
39
-export(dist2)
40
-export(decorate_heatmap_body)
41
-exportMethods(draw_heatmap_legend)
42
-exportMethods(add_heatmap)
43
-export(anno_barplot)
44
-exportMethods(row_dend)
45
-export(row_anno_boxplot)
42
+export(max_text_height)
46 43
 export(max_text_width)
47
-export(anno_link)
48
-exportMethods(make_layout)
49
-export(decorate_row_title)
50
-export(anno_histogram)
44
+export(oncoPrint)
51 45
 export(plotDataFrame)
52
-exportMethods(draw_dimnames)
46
+export(rowAnnotation)
47
+export(row_anno_barplot)
48
+export(row_anno_boxplot)
49
+export(row_anno_density)
50
+export(row_anno_histogram)
51
+export(row_anno_link)
52
+export(row_anno_points)
53
+export(row_anno_text)
54
+export(selectArea)
55
+export(unify_mat_list)
56
+exportClasses(AdditiveUnit)
57
+export(AdditiveUnit)
53 58
 exportClasses(ColorMapping)
54 59
 export(ColorMapping)
60
+exportClasses(Heatmap)
61
+export(Heatmap)
55 62
 exportClasses(HeatmapAnnotation)
56 63
 export(HeatmapAnnotation)
57
-export(anno_points)
58
-exportMethods(draw_title)
59
-export(ht_global_opt)
60
-export('+.AdditiveUnit')
61
-export(decorate_column_names)
62
-export(column_anno_barplot)
63
-export(densityHeatmap)
64
-exportMethods(heatmap_legend_size)
65 64
 exportClasses(HeatmapList)
66 65
 export(HeatmapList)
67
-export(column_anno_density)
68
-exportClasses(Heatmap)
69
-export(Heatmap)
70
-exportMethods(draw_annotation_legend)
71
-exportMethods(column_dend)
72
-exportMethods(set_component_height)
73
-export(row_anno_link)
74
-exportMethods(make_column_cluster)
75
-export(HeatmapList)
76
-exportMethods(draw_annotation)
66
+exportClasses(SingleAnnotation)
77 67
 export(SingleAnnotation)
78
-export(row_anno_histogram)
79
-exportMethods(get_color_mapping_list)
80
-exportMethods(make_row_cluster)
68
+exportMethods(add_heatmap)
69
+exportMethods(annotation_legend_size)
70
+exportMethods(color_mapping_legend)
71
+exportMethods(column_dend)
72
+exportMethods(column_order)
73
+exportMethods(component_height)
81 74
 exportMethods(component_width)
82
-export(decorate_column_title)
75
+exportMethods(draw)
76
+exportMethods(draw_annotation)
77
+exportMethods(draw_annotation_legend)
83 78
 exportMethods(draw_dend)
79
+exportMethods(draw_dimnames)
80
+exportMethods(draw_heatmap_body)
81
+exportMethods(draw_heatmap_legend)
82
+exportMethods(draw_heatmap_list)
83
+exportMethods(draw_title)
84
+exportMethods(get_color_mapping_list)
84 85
 exportMethods(get_color_mapping_param_list)
85
-export(grid.dendrogram)
86
-export(decorate_title)
87
-export(decorate_dend)
88
-export(rowAnnotation)
89
-export(column_anno_link)
90
-export(columnAnnotation)
91
-export(decorate_row_names)
92
-export(anno_text)
93
-export(anno_density)
94
-
95
-
96
-
97
-
86
+exportMethods(heatmap_legend_size)
87
+exportMethods(make_column_cluster)
88
+exportMethods(make_layout)
89
+exportMethods(make_row_cluster)
90
+exportMethods(map_to_colors)
91
+exportMethods(prepare)
92
+exportMethods(row_dend)
93
+exportMethods(row_order)
94
+exportMethods(set_component_height)
98 95
 
99 96
 import(grDevices)
100 97
 import(graphics)
... ...
@@ -113,12 +110,9 @@ importFrom("colorspace", rainbow_hcl)
113 110
 importFrom("dendextend", "labels<-")
114 111
 importFrom("dendextend", get_branches_heights)
115 112
 importFrom("dendextend", nnodes)
113
+importFrom("methods", "new", "show")
116 114
 importFrom("methods", setClass)
117 115
 importFrom("methods", setGeneric)
118 116
 importFrom("methods", setMethod)
119
-importFrom("methods", "new", "show")
120 117
 importFrom("utils", "getFromNamespace")
121 118
 
122
-
123
-
124
-
... ...
@@ -1,3 +1,24 @@
1
+CHANGES in VERSION 1.11.6
2
+
3
+* simply bump the verison number
4
+* `gap` in `Heatmap()` now can be a vector
5
+
6
+===========================
7
+
8
+CHANGES in VERSION 1.11.5
9
+
10
+* `gap` in `HeatmapAnnotation` has been adjusted
11
+* annotations support drawing names of either sides
12
+* `densityHeatmap()`: quantile lines are also reordered
13
+* export `anno_oncoprint_barplot`
14
+* `Heatmap()`: if `col` is a unnamed vector and the number of colors is same as
15
+  unique itemes in `mat`, the name of `col` vector is set to `sort(unique(mat))
16
+* adjusted the order of annotation legends
17
+* discreat legend: if a level is not in the data while defined by `col`, it will
18
+  be removed.
19
+
20
+=============================
21
+
1 22
 CHANGES in VERSION 1.11.2
2 23
 
3 24
 * `grid.dendrogram()`: do not draw dendrogram if the height is zero
... ...
@@ -25,10 +25,10 @@ setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
25 25
 
26 26
 setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
27 27
 
28
-setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
29
-
30 28
 setGeneric('get_color_mapping_param_list', function(object, ...) standardGeneric('get_color_mapping_param_list'))
31 29
 
30
+setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
31
+
32 32
 setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
33 33
 
34 34
 setGeneric('draw', function(object, ...) standardGeneric('draw'))
... ...
@@ -193,7 +193,8 @@ Heatmap = setClass("Heatmap",
193 193
 #     For each row-clusters, hierarchical clustering is still applied with parameters above.
194 194
 # -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
195 195
 #        indicating rows are to be split according to the split on the tree.
196
-# -gap gap between row-slices if the heatmap is split by rows, should be `grid::unit` object.
196
+# -gap gap between row-slices if the heatmap is split by rows, should be `grid::unit` object. If it is a vector, the order corresponds
197
+#   to top to bottom in the heatmap
197 198
 # -combined_name_fun if the heatmap is split by rows, how to make a combined row title for each slice?
198 199
 #                 The input parameter for this function is a vector which contains level names under each column in ``split``.
199 200
 # -width the width of the single heatmap, should be a fixed `grid::unit` object. It is used for the layout when the heatmap
... ...
@@ -442,7 +443,7 @@ Heatmap = function(matrix, col, name,
442 443
         } else {
443 444
             if(is.null(names(col))) {
444 445
                 if(length(col) == length(unique(as.vector(matrix)))) {
445
-                    names(col) = unique(as.vector(matrix))
446
+                    names(col) = sort(unique(as.vector(matrix)))
446 447
                     .Object@matrix_color_mapping = ColorMapping(colors = col, name = name, na_col = na_col)
447 448
                 } else if(is.numeric(matrix)) {
448 449
                     col = colorRamp2(seq(min(matrix, na.rm = TRUE), max(matrix, na.rm = TRUE), length = length(col)),
... ...
@@ -452,6 +453,7 @@ Heatmap = function(matrix, col, name,
452 453
                     stop("`col` should have names to map to values in `mat`.")
453 454
                 }
454 455
             } else {
456
+                col = col[intersect(c(names(col), "_NA_"), as.character(matrix))]
455 457
                 .Object@matrix_color_mapping = ColorMapping(colors = col, name = name, na_col = na_col)
456 458
             }
457 459
         }
... ...
@@ -648,6 +650,12 @@ setMethod(f = "make_column_cluster",
648 650
     signature = "Heatmap",
649 651
     definition = function(object) {
650 652
     
653
+    if(ht_global_opt("fast_hclust")) {
654
+        hclust = fastcluster::hclust
655
+    } else {
656
+        hclust = stats::hclust
657
+    }
658
+    
651 659
     mat = object@matrix
652 660
     distance = object@column_dend_param$distance
653 661
     method = object@column_dend_param$method
... ...
@@ -730,6 +738,12 @@ setMethod(f = "make_row_cluster",
730 738
     signature = "Heatmap",
731 739
     definition = function(object) {
732 740
 
741
+    if(ht_global_opt("fast_hclust")) {
742
+        hclust = fastcluster::hclust
743
+    } else {
744
+        hclust = stats::hclust
745
+    }
746
+
733 747
     mat = object@matrix
734 748
     distance = object@row_dend_param$distance
735 749
     method = object@row_dend_param$method
... ...
@@ -963,14 +977,26 @@ setMethod(f = "make_layout",
963 977
     # position of each row-slice
964 978
     gap = object@matrix_param$gap
965 979
     n_slice = length(object@row_order_list)
980
+    if(length(gap) == 1) {
981
+        gap = rep(gap, n_slice)
982
+    } else if(length(gap) == n_slice - 1) {
983
+        gap = unit.c(gap, unit(0, "mm"))
984
+    } else if(length(gap) != n_slice) {
985
+        stop("Length of `gap` should be 1 or number of row slices.")
986
+    }
987
+
966 988
     snr = sapply(object@row_order_list, length)
967 989
     if(sum(snr)) {
968
-        slice_height = (unit(1, "npc") - gap*(n_slice-1))*(snr/sum(snr))
990
+        if(n_slice == 1) {
991
+            slice_height = unit(1, "npc")*(snr/sum(snr))
992
+            } else {
993
+                slice_height = (unit(1, "npc") - sum(gap[seq_len(n_slice-1)]))*(snr/sum(snr))
994
+            }  
969 995
         for(i in seq_len(n_slice)) {
970 996
             if(i == 1) {
971 997
                 slice_y = unit(1, "npc")
972 998
             } else {
973
-                slice_y = unit.c(slice_y, unit(1, "npc") - sum(slice_height[seq_len(i-1)]) - gap*(i-1))
999
+                slice_y = unit.c(slice_y, unit(1, "npc") - sum(slice_height[seq_len(i-1)]) - sum(gap[seq_len(i-1)]))
974 1000
             }
975 1001
         }
976 1002
 
... ...
@@ -52,6 +52,12 @@ HeatmapAnnotation = setClass("HeatmapAnnotation",
52 52
 # -width width of the whole heatmap annotations, only used for row annotation when appending to the list of heatmaps.
53 53
 # -gp graphic parameters for simple annotations.
54 54
 # -gap gap between each annotation
55
+# -show_annotation_name whether show annotation names. For column annotation, annotation names are drawn either on the left
56
+#   or the right, and for row annotations, names are draw either on top to at bottom. The value can be a vector.
57
+# -annotation_name_gp graphic parameters for anntation names. Graphic paramters can be vectors.
58
+# -annotation_name_offset offset to the annotations, `grid::unit` object. The value can be a vector.
59
+# -annotation_name_side side of the annotation names.
60
+# -annotation_name_rot rotation of the annotation names, can only take values in ``c(00, 90, 180, 270)``. The value can be a vector.
55 61
 #
56 62
 # == details
57 63
 # The simple annotations are defined by ``df`` and ``col`` arguments. Complex annotations are
... ...
@@ -76,7 +82,12 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
76 82
 	height = calc_anno_size(), 
77 83
 	width = calc_anno_size(), 
78 84
 	gp = gpar(col = NA),
79
-	gap = unit(0, "mm")) {
85
+	gap = unit(0, "mm"),
86
+	show_annotation_name = FALSE,
87
+	annotation_name_gp = gpar(),
88
+	annotation_name_offset = unit(2, "mm"),
89
+	annotation_name_side = ifelse(which == "column", "right", "bottom"),
90
+	annotation_name_rot = ifelse(which == "column", 0, 90)) {
80 91
 
81 92
 	.Object = new("HeatmapAnnotation")
82 93
 
... ...
@@ -94,7 +105,8 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
94 105
     arg_list = as.list(match.call())[-1]
95 106
     called_args = names(arg_list)
96 107
     anno_args = setdiff(called_args, c("name", "col", "na_col", "annotation_legend_param", "show_legend", "which", 
97
-    	                             "annotation_height", "annotation_width", "height", "width", "gp", "gap"))
108
+    	                             "annotation_height", "annotation_width", "height", "width", "gp", "gap",
109
+    	                             "show_annotation_name", "annotation_name_gp", "annotation_name_offset", "annotation_name_side", "annotation_name_rot"))
98 110
     if(any(anno_args == "")) stop("annotations should have names.")
99 111
     if(any(duplicated(anno_args))) stop("names of annotations should be unique.")
100 112
     anno_arg_list = list(...)
... ...
@@ -143,7 +155,30 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
143 155
 		}
144 156
 	}
145 157
 
158
+	n_total_anno = 0
159
+	for(ag in anno_args) {
160
+		if(ag == "df") {
161
+			n_total_anno = n_total_anno + ncol(df)
162
+		} else {
163
+			n_total_anno = n_total_anno + 1
164
+		}
165
+	}
166
+	if(length(show_annotation_name) == 1) {
167
+    	show_annotation_name = rep(show_annotation_name, n_total_anno)
168
+    }
169
+    if(length(annotation_name_offset) == 1) {
170
+    	annotation_name_offset = rep(annotation_name_offset, n_total_anno)
171
+    }
172
+    if(length(annotation_name_side) == 1) {
173
+    	annotation_name_side = rep(annotation_name_side, n_total_anno)
174
+    }
175
+    if(length(annotation_name_rot) == 1) {
176
+    	annotation_name_rot = rep(annotation_name_rot, n_total_anno)
177
+    }
178
+    annotation_name_gp = recycle_gp(annotation_name_gp, n_total_anno)
179
+
146 180
 	i_simple = 0
181
+	i_anno = 0
147 182
 	simple_length = NULL
148 183
     for(ag in anno_args) {
149 184
 		if(ag == "df") {
... ...
@@ -161,21 +196,35 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
161 196
 
162 197
 		    if(missing(col)) {
163 198
 		        for(i in seq_len(n_anno)) {
164
-		        	anno_list = c(anno_list, list(SingleAnnotation(name = anno_name[i], value = df[, i], na_col = na_col, which = which, show_legend = show_legend[i_simple + i], gp = gp, legend_param = annotation_legend_param[[i_simple + i]])))
199
+		        	i_anno = i_anno + 1
200
+		        	anno_list = c(anno_list, list(SingleAnnotation(name = anno_name[i], value = df[, i], na_col = na_col, which = which, 
201
+		        		show_legend = show_legend[i_simple + i], gp = gp, legend_param = annotation_legend_param[[i_simple + i]],
202
+		        		show_name = show_annotation_name[i_anno], name_gp = subset_gp(annotation_name_gp, i_anno), 
203
+		        		name_offset = annotation_name_offset[i_anno], name_side = annotation_name_side[i_anno], name_rot = annotation_name_rot[i_anno])))
165 204
 		        }
166 205
 		    } else {
167 206
 		        for(i in seq_len(n_anno)) {
207
+		        	i_anno = i_anno + 1
168 208
 		        	if(is.null(col[[ anno_name[i] ]])) { # if the color is not provided
169
-		        		anno_list = c(anno_list, list(SingleAnnotation(name = anno_name[i], value = df[, i], na_col = na_col, which = which, show_legend = show_legend[i_simple + i], gp = gp, legend_param = annotation_legend_param[[i_simple + i]])))
209
+		        		anno_list = c(anno_list, list(SingleAnnotation(name = anno_name[i], value = df[, i], na_col = na_col, which = which, 
210
+		        			show_legend = show_legend[i_simple + i], gp = gp, legend_param = annotation_legend_param[[i_simple + i]],
211
+		        			show_name = show_annotation_name[i_anno], name_gp = subset_gp(annotation_name_gp, i_anno), 
212
+		        			name_offset = annotation_name_offset[i_anno], name_side = annotation_name_side[i_anno], name_rot = annotation_name_rot[i_anno])))
170 213
 		        	} else {
171
-		        		anno_list = c(anno_list, list(SingleAnnotation(name = anno_name[i], value = df[, i], na_col = na_col, col = col[[ anno_name[i] ]], which = which, show_legend = show_legend[i_simple + i], gp = gp, legend_param = annotation_legend_param[[i_simple + i]])))
214
+		        		anno_list = c(anno_list, list(SingleAnnotation(name = anno_name[i], value = df[, i], na_col = na_col, col = col[[ anno_name[i] ]], 
215
+		        			which = which, show_legend = show_legend[i_simple + i], gp = gp, legend_param = annotation_legend_param[[i_simple + i]],
216
+		        			show_name = show_annotation_name[i_anno], name_gp = subset_gp(annotation_name_gp, i_anno), 
217
+		        			name_offset = annotation_name_offset[i_anno], name_side = annotation_name_side[i_anno], name_rot = annotation_name_rot[i_anno])))
172 218
 		        	}
173 219
 		        }
174 220
 		    }
175 221
 		    i_simple = i_simple + n_anno
176 222
 		} else {
223
+			i_anno = i_anno + 1
177 224
 			if(inherits(anno_arg_list[[ag]], "function")) {
178
-				anno_list = c(anno_list, list(SingleAnnotation(name = ag, fun = anno_arg_list[[ag]], which = which)))
225
+				anno_list = c(anno_list, list(SingleAnnotation(name = ag, fun = anno_arg_list[[ag]], which = which,
226
+					show_name = show_annotation_name[i_anno], name_gp = subset_gp(annotation_name_gp, i_anno), 
227
+		        	name_offset = annotation_name_offset[i_anno], name_side = annotation_name_side[i_anno], name_rot = annotation_name_rot[i_anno])))
179 228
 			} else if(is.atomic(anno_arg_list[[ag]])) {
180 229
 
181 230
 			    if(is.null(simple_length)) {
... ...
@@ -184,12 +233,21 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
184 233
 			    	stop("length of simple annotations differ.")
185 234
 			    }
186 235
 				if(missing(col)) {
187
-			        anno_list = c(anno_list, list(SingleAnnotation(name = ag, value = anno_arg_list[[ag]], na_col = na_col, which = which, show_legend = show_legend[i_simple + 1], gp = gp, legend_param = annotation_legend_param[[i_simple + 1]])))
236
+			        anno_list = c(anno_list, list(SingleAnnotation(name = ag, value = anno_arg_list[[ag]], na_col = na_col, which = which, 
237
+			        	show_legend = show_legend[i_simple + 1], gp = gp, legend_param = annotation_legend_param[[i_simple + 1]],
238
+			        	show_name = show_annotation_name[i_anno], name_gp = subset_gp(annotation_name_gp, i_anno), 
239
+		        		name_offset = annotation_name_offset[i_anno], name_side = annotation_name_side[i_anno], name_rot = annotation_name_rot[i_anno])))
188 240
 			    } else {
189 241
 			        if(is.null(col[[ ag ]])) { # if the color is not provided
190
-			        	anno_list = c(anno_list, list(SingleAnnotation(name = ag, value = anno_arg_list[[ag]], na_col = na_col, which = which, show_legend = show_legend[i_simple + 1], gp = gp, legend_param = annotation_legend_param[[i_simple + 1]])))
242
+			        	anno_list = c(anno_list, list(SingleAnnotation(name = ag, value = anno_arg_list[[ag]], na_col = na_col, which = which, 
243
+			        		show_legend = show_legend[i_simple + 1], gp = gp, legend_param = annotation_legend_param[[i_simple + 1]],
244
+			        		show_name = show_annotation_name[i_anno], name_gp = subset_gp(annotation_name_gp, i_anno), 
245
+		        		name_offset = annotation_name_offset[i_anno], name_side = annotation_name_side[i_anno], name_rot = annotation_name_rot[i_anno])))
191 246
 			        } else {
192
-			        	anno_list = c(anno_list, list(SingleAnnotation(name = ag, value = anno_arg_list[[ag]], na_col = na_col, col = col[[ ag ]], which = which, show_legend = show_legend[i_simple + 1], gp = gp, legend_param = annotation_legend_param[[i_simple + 1]])))
247
+			        	anno_list = c(anno_list, list(SingleAnnotation(name = ag, value = anno_arg_list[[ag]], na_col = na_col, col = col[[ ag ]], 
248
+			        		which = which, show_legend = show_legend[i_simple + 1], gp = gp, legend_param = annotation_legend_param[[i_simple + 1]],
249
+			        		show_name = show_annotation_name[i_anno], name_gp = subset_gp(annotation_name_gp, i_anno), 
250
+		        			name_offset = annotation_name_offset[i_anno], name_side = annotation_name_side[i_anno], name_rot = annotation_name_rot[i_anno])))
193 251
 			        }
194 252
 			    }
195 253
 			    i_simple = i_simple + 1
... ...
@@ -199,21 +257,19 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
199 257
 		}
200 258
 	}
201 259
 
202
-	if(which == "column") {
203
-		anno_list = rev(anno_list)
204
-	}
205
-
206
-	n_anno = length(anno_list)
260
+	n_total_anno = length(anno_list)
207 261
 
208 262
 	if(is.null(gap)) gap = unit(0, "mm")
209 263
 
264
+	# the nth gap does not really matter
210 265
     if(length(gap) == 1) {
211
-    	.Object@gap = rep(gap, n_anno)
212
-    } else if(length(gap) == n_anno - 1) {
266
+    	.Object@gap = rep(gap, n_total_anno)
267
+    } else if(length(gap) == n_total_anno - 1) {
213 268
     	.Object@gap = unit.c(gap, unit(0, "mm"))
214
-    } else if(length(gap) < n_anno - 1) {
269
+    } else if(length(gap) < n_total_anno - 1) {
215 270
     	stop("Length of `gap` is wrong.")
216 271
     } else {
272
+    	gap[n_total_anno] = unit(0, "mm")
217 273
     	.Object@gap = gap
218 274
     }
219 275
 
... ...
@@ -223,7 +279,7 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
223 279
 
224 280
 	if(length(anno_size) == 1) {
225 281
 		if(!is.unit(anno_size)) {
226
-			anno_size = rep(anno_size, n_anno)
282
+			anno_size = rep(anno_size, n_total_anno)
227 283
 		}
228 284
 	}
229 285
 
... ...
@@ -231,8 +287,6 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
231 287
 		anno_size = anno_size/sum(anno_size)*(unit(1, "npc") - sum(.Object@gap))
232 288
 	}
233 289
 
234
-	if(which == "column") anno_size = anno_size[rev(seq_len(n_anno))]
235
-
236 290
 	names(anno_list) = sapply(anno_list, function(x) x@name)
237 291
     .Object@anno_list = anno_list
238 292
     .Object@anno_size = anno_size
... ...
@@ -262,12 +316,11 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
262 316
 #
263 317
 # == param
264 318
 # -... pass to `HeatmapAnnotation`
265
-# -width default width of the row annotations
266 319
 #
267 320
 # == details
268 321
 # The function is identical to 
269 322
 #
270
-#     HeatmapAnnotation(..., which = "row", width = width)
323
+#     HeatmapAnnotation(..., which = "row")
271 324
 #
272 325
 # == value
273 326
 # A `HeatmapAnnotation-class` object.
... ...
@@ -275,8 +328,8 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
275 328
 # == author
276 329
 # Zuguang Gu <z.gu@dkfz.de>
277 330
 #
278
-rowAnnotation = function(..., width = unit(1, "cm")) {
279
-	HeatmapAnnotation(..., which = "row", width = width)
331
+rowAnnotation = function(...) {
332
+	HeatmapAnnotation(..., which = "row")
280 333
 }
281 334
 
282 335
 # == title
... ...
@@ -391,18 +444,30 @@ setMethod(f = "draw",
391 444
 	gap = object@gap
392 445
 
393 446
 	pushViewport(viewport(...))
394
-	for(i in seq_len(n_anno)) {
395
-		if(which == "column") {
396
-			if(align_to == "bottom") {
397
-				pushViewport(viewport(y = sum(anno_size[seq_len(i)]) + sum(gap[seq_len(i)]) - gap[i], height = anno_size[i], just = c("center", "top")))
398
-			} else {
399
-				pushViewport(viewport(y = unit(1, "npc") - (sum(anno_size[seq(i, n_anno)]) + sum(gap[seq(i, n_anno)]) - gap[n_anno + 1 - i]), height = anno_size[i], just = c("center", "bottom")))
447
+	if(which == "column") {
448
+		if(align_to == "bottom") { # put on top of the heatmap
449
+			# start from the last annoation which is put on bottom
450
+			for(i in seq_len(n_anno)) {
451
+				pushViewport(viewport(y = sum(anno_size[seq(i, n_anno)]) + sum(gap[seq(i, n_anno)]) - gap[n_anno], 
452
+					height = anno_size[i], just = c("center", "top")))
453
+				draw(object@anno_list[[i]], index, k, n)
454
+				upViewport()
400 455
 			}
401
-		} else {
456
+		} else { # put on bottom of the heatmap
457
+			# start for the first annotation which is put on the top
458
+			for(i in seq_len(n_anno)) {
459
+				pushViewport(viewport(y = unit(1, "npc") - (sum(anno_size[seq_len(i)]) + sum(gap[seq_len(i)]) - gap[i]), 
460
+					height = anno_size[i], just = c("center", "bottom")))
461
+				draw(object@anno_list[[i]], index, k, n)
462
+				upViewport()
463
+			}
464
+		}
465
+	} else if(which == "row") {
466
+		for(i in seq_len(n_anno)) {
402 467
 			pushViewport(viewport(x = sum(anno_size[seq_len(i)]) + sum(gap[seq_len(i)]) - gap[i], width = anno_size[i], just = c("right", "center")))
468
+			draw(object@anno_list[[i]], index, k, n)
469
+			upViewport()
403 470
 		}
404
-		draw(object@anno_list[[i]], index, k, n)
405
-		upViewport()
406 471
 	}
407 472
 	upViewport()
408 473
 })
... ...
@@ -1195,11 +1195,11 @@ setMethod(f = "draw_annotation_legend",
1195 1195
         ht = object@ht_list[[i]]
1196 1196
         if(inherits(ht, "Heatmap")) {
1197 1197
             if(!is.null(ht@top_annotation)) {
1198
-                ColorMappingList = c.list(get_color_mapping_list(ht@top_annotation), list = ColorMappingList)
1198
+                ColorMappingList = c.list(ColorMappingList, list = get_color_mapping_list(ht@top_annotation))
1199 1199
                 ColorMappingParamList = c.list(ColorMappingParamList, list = get_color_mapping_param_list(ht@top_annotation))
1200 1200
             }
1201 1201
             if(!is.null(ht@bottom_annotation)) {
1202
-                ColorMappingList = c.list(get_color_mapping_list(ht@bottom_annotation), list = ColorMappingList)
1202
+                ColorMappingList = c.list(ColorMappingList, list = get_color_mapping_list(ht@bottom_annotation))
1203 1203
                 ColorMappingParamList = c.list(ColorMappingParamList, list = get_color_mapping_param_list(ht@bottom_annotation))
1204 1204
             }
1205 1205
         }
... ...
@@ -1222,7 +1222,8 @@ setMethod(f = "draw_annotation_legend",
1222 1222
             pushViewport(viewport(name = "annotation_legend", x = x, y = unit(0.5, "npc"), width = size[1], height = size[2], just = c("left", "center")))           
1223 1223
         }
1224 1224
     }
1225
-    draw_legend(rev(ColorMappingList), rev(ColorMappingParamList), side = side, legend_list = legend_list, padding = padding, ...)
1225
+
1226
+    draw_legend(ColorMappingList, ColorMappingParamList, side = side, legend_list = legend_list, padding = padding, ...)
1226 1227
     upViewport()
1227 1228
 })
1228 1229
 
... ...
@@ -1312,7 +1313,7 @@ setMethod(f = "annotation_legend_size",
1312 1313
         }
1313 1314
     }
1314 1315
 
1315
-    size = draw_legend(rev(ColorMappingList), rev(ColorMappingParamList), side = side, plot = FALSE, legend_list = legend_list, padding = padding, ...)
1316
+    size = draw_legend(ColorMappingList, ColorMappingParamList, side = side, plot = FALSE, legend_list = legend_list, padding = padding, ...)
1316 1317
     
1317 1318
     return(size)
1318 1319
 })
... ...
@@ -40,7 +40,7 @@ Legend = function(at, labels = at, nrow = NULL, ncol = 1, col_fun,
40 40
 	title = "", title_gp = gpar(fontsize = 10, fontface = "bold"), 
41 41
 	title_position = c("topleft", "topcenter", "leftcenter", "lefttop")) {
42 42
 
43
-	odevlist = dev.list()
43
+	# odevlist = dev.list()
44 44
 
45 45
 	if(missing(col_fun)) {
46 46
 		if(is.null(border)) border = "white"
... ...
@@ -128,9 +128,9 @@ Legend = function(at, labels = at, nrow = NULL, ncol = 1, col_fun,
128 128
 		}
129 129
 	}
130 130
 
131
-	for(i in seq_len(length(odevlist) - length(dev.list()))) {
132
-		dev.off()
133
-	}
131
+	# for(i in seq_len(length(odevlist) - length(dev.list()))) {
132
+	# 	dev.off()
133
+	# }
134 134
 
135 135
 	return(gf)
136 136
 }
... ...
@@ -61,6 +61,11 @@ SingleAnnotation = setClass("SingleAnnotation",
61 61
 # -show_legend if it is a simple annotation, whether show legend when making the complete heatmap.
62 62
 # -gp Since simple annotation is represented as a row of grids. This argument controls graphic parameters for the simple annotation.
63 63
 # -legend_param parameters for the legend. See `color_mapping_legend,ColorMapping-method` for options.
64
+# -show_name whether show annotation name
65
+# -name_gp graphic parameters for annotation name
66
+# -name_offset offset to the annotation, a `grid::unit` object
67
+# -name_side 'right' and 'left' for column annotations and 'top' and 'bottom' for row annotations
68
+# -name_rot rotation of the annotation name, can only take values in ``c(00, 90, 180, 270)``.
64 69
 #
65 70
 # == details
66 71
 # The most simple annotation is one row or one column grids in which different colors
... ...
@@ -95,11 +100,11 @@ SingleAnnotation = function(name, value, col, fun,
95 100
 	show_legend = TRUE, 
96 101
 	gp = gpar(col = NA), 
97 102
 	legend_param = list(),
98
-	show_name = TRUE, 
103
+	show_name = FALSE, 
99 104
 	name_gp = gpar(fontsize = 12),
100 105
 	name_offset = unit(2, "mm"),
101
-	name_rot = 0,
102
-	name_side = ifelse(which == "column", "right", "bottom")) {
106
+	name_side = ifelse(which == "column", "right", "bottom"),
107
+    name_rot = ifelse(which == "column", 0, 90)) {
103 108
 
104 109
 	# re-define some of the argument values according to global settings
105 110
     called_args = names(as.list(match.call())[-1])
... ...
@@ -127,11 +132,77 @@ SingleAnnotation = function(name, value, col, fun,
127 132
         increase_annotation_index()
128 133
     }
129 134
     .Object@name = name
135
+
136
+    if(!name_rot %in% c(0, 90, 180, 270)) {
137
+        stop("`name_rot` can only take values in c(0, 90, 180, 270)")
138
+    }
139
+
140
+    
141
+    if(which == "column") {
142
+    	if(!name_side %in% c("left", "right")) {
143
+    		stop("`name_side` should be 'left' or 'right' when it is a column annotation.")
144
+    	}
145
+    	if(name_side == "left") {
146
+    		name_x = unit(0, "npc") - name_offset
147
+    		name_y = unit(0.5, "npc")
148
+            if(name_rot == 0) {
149
+                name_just = "right"
150
+            } else if(name_rot == 90) {
151
+                name_just = "bottom"
152
+            } else if(name_rot == 180) {
153
+                name_just = "left"
154
+            } else {
155
+                name_just = "top"
156
+            }
157
+    	} else {
158
+    		name_x = unit(1, "npc") + name_offset
159
+    		name_y = unit(0.5, "npc")
160
+            if(name_rot == 0) {
161
+                name_just = "left"
162
+            } else if(name_rot == 90) {
163
+                name_just = "top"
164
+            } else if(name_rot == 180) {
165
+                name_just = "right"
166
+            } else {
167
+                name_just = "bottom"
168
+            }
169
+    	}
170
+    } else if(which == "row") {
171
+    	if(!name_side %in% c("top", "bottom")) {
172
+    		stop("`name_side` should be 'left' or 'right' when it is a column annotation.")
173
+    	}
174
+    	if(name_side == "top") {
175
+    		name_x = unit(0.5, "npc")
176
+    		name_y = unit(1, "npc") + name_offset
177
+            if(name_rot == 0) {
178
+                name_just = "bottom"
179
+            } else if(name_rot == 90) {
180
+                name_just = "left"
181
+            } else if(name_rot == 180) {
182
+                name_just = "top"
183
+            } else {
184
+                name_just = "right"
185
+            }
186
+    	} else {
187
+    		name_x = unit(0.5, "npc")
188
+    		name_y = unit(0, "npc") - name_offset
189
+            if(name_rot == 0) {
190
+                name_just = "top"
191
+            } else if(name_rot == 90) {
192
+                name_just = "right"
193
+            } else if(name_rot == 180) {
194
+                name_just = "bottom"
195
+            } else {
196
+                name_just = "left"
197
+            }
198
+    	}
199
+    }
130 200
     .Object@name_param = list(show = show_name,
201
+    						  x = name_x,
202
+    						  y = name_y,
203
+    						  just = name_just,
131 204
     	                      gp = check_gp(name_gp),
132
-    	                      offset = name_offset,
133
-    	                      rot = name_rot,
134
-    	                      side = name_side)
205
+    	                      rot = name_rot)
135 206
 
136 207
     gp = check_gp(gp)
137 208
     if(!is.null(gp$fill)) {
... ...
@@ -152,6 +223,7 @@ SingleAnnotation = function(name, value, col, fun,
152 223
     		col = default_col(value)
153 224
     	}
154 225
     	if(is.atomic(col)) {
226
+            col = col[intersect(c(names(col), "_NA_"), as.character(value))]
155 227
     		if("_NA_" %in% names(col)) {
156 228
     			na_col = col["_NA_"]
157 229
     			col = col[names(col) != "_NA_"]
... ...
@@ -260,6 +332,11 @@ setMethod(f = "draw",
260 332
 			object@fun(index, k, n)
261 333
 		}
262 334
 	}
335
+	# add annotation name
336
+	if(object@name_param$show) {
337
+		grid.text(object@name, x = object@name_param$x, y = object@name_param$y, just = object@name_param$just, 
338
+			rot = object@name_param$rot, gp = object@name_param$gp)
339
+	}
263 340
 	upViewport()
264 341
 
265 342
 })
... ...
@@ -77,9 +77,11 @@ densityHeatmap = function(data,
77 77
 	if(is.matrix(data)) {
78 78
 		density_list = apply(data, 2, density, na.rm = TRUE)
79 79
 		quantile_list = apply(data, 2, quantile, na.rm = TRUE)
80
+		mean_value = apply(data, 2, mean, na.rm = TRUE)
80 81
 	} else if(is.data.frame(data) || is.list(data)) {
81 82
 		density_list = lapply(data, density, na.rm = TRUE)
82 83
 		quantile_list = sapply(data, quantile, na.rm = TRUE)
84
+		mean_value = sapply(data, mean, na.rm = TRUE)
83 85
 	} else {
84 86
 		stop("only matrix and list are allowed.")
85 87
 	}
... ...
@@ -160,6 +162,7 @@ densityHeatmap = function(data,
160 162
 		ht + rowAnnotation(quantile = function(index) NULL, width = grobWidth(textGrob("100%")))
161 163
 
162 164
 	ht_list = draw(ht_list, column_title = title, ...)
165
+	column_order = column_order(ht_list)$density
163 166
 
164 167
 	decorate_annotation("axis", {
165 168
 		grid.text(ylab, x = grobHeight(textGrob(ylab)), rot = 90)
... ...
@@ -169,10 +172,13 @@ densityHeatmap = function(data,
169 172
 		pushViewport(viewport(xscale = c(0.5, n + 0.5), yscale = c(min_x, max_x)))
170 173
 		grid.rect(gp = gpar(fill = NA))
171 174
 		grid.yaxis()
175
+
172 176
 		for(i in seq_len(5)) {
173
-			grid.lines(1:n, quantile_list[i, ], default.units = "native", gp = gpar(lty = 2))
177
+			grid.lines(1:n, quantile_list[i, column_order], default.units = "native", gp = gpar(lty = 2))
174 178
 			grid.text(rownames(quantile_list)[i], unit(1, "npc")+unit(2, "mm"), quantile_list[i, n], default.units = "native", just = "left")
175 179
 		}
180
+		grid.lines(1:n, mean_value[column_order], default.units = "native", gp = gpar(lty = 2, col = "darkred"))
181
+		grid.text("mean", unit(1, "npc")+unit(2, "mm"), mean_value[n], default.units = "native", just = "left")
176 182
 		upViewport()
177 183
 	})
178 184
 
... ...
@@ -66,7 +66,7 @@ enhanced_basicplot = function(data, ..., ylim = NULL,
66 66
         }
67 67
     }
68 68
 
69
-    mat_foo = matrix("", nrow = 2, ncol = n)
69
+    mat_foo = matrix("foo", nrow = 2, ncol = n)
70 70
     if(is.matrix(data)) {
71 71
         colnames(mat_foo) = colnames(data)
72 72
     } else if(is.list(data)) {
... ...
@@ -75,7 +75,7 @@ enhanced_basicplot = function(data, ..., ylim = NULL,
75 75
         colnames(mat_foo) = names(data)
76 76
     }
77 77
         
78
-    ht = Heatmap(mat_foo, name = "main", cluster_rows = FALSE, cluster_columns = FALSE,
78
+    ht = Heatmap(mat_foo, col = c("foo" = "white"), name = "main", cluster_rows = FALSE, cluster_columns = FALSE,
79 79
                 rect_gp = gpar(type = "none"), show_heatmap_legend = FALSE, ...)
80 80
 
81 81
     draw(ht, padding = padding, column_title = title, column_title_gp = title_gp,
... ...
@@ -33,6 +33,7 @@
33 33
 # -heatmap_legend_grid_width set ``grid_width`` element in ``legend_param`` in `SingleAnnotation`.
34 34
 # -heatmap_legend_grid_height set ``grid_height`` element in ``legend_param`` in `SingleAnnotation`.
35 35
 # -heatmap_legend_grid_border set ``grid_border`` element in ``legend_param`` in `SingleAnnotation`.
36
+# -fast_hclust whether use `fastcluster::hclust` to speed up clustering?
36 37
 #
37 38
 # You can get or set option values by the traditional way (like `base::options`) or by ``$`` operator:
38 39
 #
... ...
@@ -103,5 +104,10 @@ ht_global_opt = setGlobalOptions(
103 104
 		.value = NULL,
104 105
 		.class = "unit"),
105 106
 	annotation_legend_grid_border = list(
106
-		.value = NULL)
107
+		.value = NULL),
108
+	fast_hclust = list(
109
+		.value = FALSE,
110
+		.class = "logical",
111
+		.length = 1
112
+	)
107 113
 )
... ...
@@ -58,7 +58,7 @@ oncoPrint = function(mat, get_type = function(x) x,
58 58
 	row_barplot_width = unit(2, "cm"),
59 59
 	remove_empty_columns = FALSE,
60 60
 	heatmap_legend_param = list(title = "Alterations"),
61
-	top_annotation = HeatmapAnnotation(column_bar = anno_column_bar, 
61
+	top_annotation = HeatmapAnnotation(column_bar = anno_oncoprint_barplot(), 
62 62
 		annotation_height = unit(2, "cm")),
63 63
 	barplot_ignore = NULL,
64 64
 	...) {
... ...
@@ -286,6 +286,13 @@ oncoPrint = function(mat, get_type = function(x) x,
286 286
 		top_annotation = top_annotation,
287 287
 		heatmap_legend_param = heatmap_legend_param, ...)
288 288
 
289
+	ht@matrix_param$oncoprint = list()
290
+	ht@matrix_param$oncoprint$arr = arr
291
+	ht@matrix_param$oncoprint$barplot_ignore = barplot_ignore
292
+	ht@matrix_param$oncoprint$all_type = all_type
293
+	ht@matrix_param$oncoprint$axis_gp = axis_gp
294
+	ht@matrix_param$oncoprint$col = col
295
+
289 296
 	if(show_pct) {
290 297
 		ht_list = ha_pct + ht
291 298
 	} else {
... ...
@@ -331,3 +338,45 @@ unify_mat_list = function(mat_list, default = 0) {
331 338
 }
332 339
 
333 340
 
341
+
342
+# == title
343
+# Column barplot annotaiton for oncoPrint
344
+#
345
+# == details
346
+# This function is only used for column annotation
347
+#
348
+# == author
349
+# Zuguang Gu <z.gu@dkfz.de>
350
+#
351
+anno_oncoprint_barplot = function() {
352
+
353
+	function(index) {
354
+		object = get("object", envir = parent.frame(n = 5))
355
+		arr = object@matrix_param$oncoprint$arr
356
+		barplot_ignore = object@matrix_param$oncoprint$barplot_ignore
357
+		all_type = object@matrix_param$oncoprint$all_type
358
+		axis_gp = object@matrix_param$oncoprint$axis_gp
359
+		col = object@matrix_param$oncoprint$col
360
+
361
+		n = length(index)
362
+		count = apply(arr, c(2, 3), sum)[index, , drop = FALSE]
363
+		all_type = all_type[!(colnames(count) %in% barplot_ignore)]
364
+		count = count[, setdiff(colnames(count), barplot_ignore), drop = FALSE]
365
+		max_count = max(rowSums(count))
366
+		pushViewport(viewport(yscale = c(0, max_count*1.1), xscale = c(0.5, n + 0.5)))
367
+		for(i in seq_len(nrow(count))) {
368
+			if(any(count[i, ] > 0)) {
369
+				y = count[i, ]
370
+				y = y[y > 0]
371
+				y2 = cumsum(y)
372
+				type = all_type[count[i, ] > 0]
373
+				grid.rect(i, y2, height = y, width = 0.8, default.units = "native", just = "top", gp = gpar(col = NA, fill = col[type]))
374
+			}
375
+		}
376
+		breaks = grid.pretty(c(0, max_count))
377
+		grid.yaxis(at = breaks, label = breaks, gp = axis_gp)
378
+		upViewport()
379
+	}
380
+}
381
+
382
+
... ...
@@ -39,7 +39,6 @@ increase_color_mapping_index = function() {
39 39
     INDEX_ENV$I_COLOR_MAPPING = INDEX_ENV$I_COLOR_MAPPING + 1
40 40
 }
41 41
 
42
-
43 42
 # default colors for matrix or annotations
44 43
 # this function should be improved later
45 44
 default_col = function(x, main_matrix = FALSE) {
... ...
@@ -17,7 +17,12 @@ HeatmapAnnotation(df, name, col, na_col = "grey",
17 17
     height = calc_anno_size(),
18 18
     width = calc_anno_size(),
19 19
     gp = gpar(col = NA),
20
-    gap = unit(0, "mm"))
20
+    gap = unit(0, "mm"),
21
+    show_annotation_name = FALSE,
22
+    annotation_name_gp = gpar(),
23
+    annotation_name_offset = unit(2, "mm"),
24
+    annotation_name_side = ifelse(which == "column", "right", "bottom"),
25
+    annotation_name_rot = ifelse(which == "column", 0, 90))
21 26
 }
22 27
 \arguments{
23 28
 
... ...
@@ -35,6 +40,11 @@ HeatmapAnnotation(df, name, col, na_col = "grey",
35 40
   \item{width}{width of the whole heatmap annotations, only used for row annotation when appending to the list of heatmaps.}
36 41
   \item{gp}{graphic parameters for simple annotations.}
37 42
   \item{gap}{gap between each annotation}
43
+  \item{show_annotation_name}{whether show annotation names. For column annotation, annotation names are drawn either on the left or the right, and for row annotations, names are draw either on top to at bottom. The value can be a vector.}
44
+  \item{annotation_name_gp}{graphic parameters for anntation names. Graphic paramters can be vectors.}
45
+  \item{annotation_name_offset}{offset to the annotations, \code{\link[grid]{unit}} object. The value can be a vector.}
46
+  \item{annotation_name_side}{side of the annotation names.}
47
+  \item{annotation_name_rot}{rotation of the annotation names, can only take values in \code{c(00, 90, 180, 270)}. The value can be a vector.}
38 48
 
39 49
 }
40 50
 \details{
... ...
@@ -12,7 +12,12 @@ SingleAnnotation(name, value, col, fun,
12 12
     which = c("column", "row"),
13 13
     show_legend = TRUE,
14 14
     gp = gpar(col = NA),
15
-    legend_param = list())
15
+    legend_param = list(),
16
+    show_name = FALSE,
17
+    name_gp = gpar(fontsize = 12),
18
+    name_offset = unit(2, "mm"),
19
+    name_side = ifelse(which == "column", "right", "bottom"),
20
+    name_rot = ifelse(which == "column", 0, 90))
16 21
 }
17 22
 \arguments{
18 23
 
... ...
@@ -25,6 +30,11 @@ SingleAnnotation(name, value, col, fun,
25 30
   \item{show_legend}{if it is a simple annotation, whether show legend when making the complete heatmap.}
26 31
   \item{gp}{Since simple annotation is represented as a row of grids. This argument controls graphic parameters for the simple annotation.}
27 32
   \item{legend_param}{parameters for the legend. See \code{\link{color_mapping_legend,ColorMapping-method}} for options.}
33
+  \item{show_name}{whether show annotation name}
34
+  \item{name_gp}{graphic parameters for annotation name}
35
+  \item{name_offset}{offset to the annotation, a \code{\link[grid]{unit}} object}
36
+  \item{name_side}{'right' and 'left' for column annotations and 'top' and 'bottom' for row annotations}
37
+  \item{name_rot}{rotation of the annotation name, can only take values in \code{c(00, 90, 180, 270)}.}
28 38
 
29 39
 }
30 40
 \details{
31 41
new file mode 100644
... ...
@@ -0,0 +1,22 @@
1
+\name{anno_oncoprint_barplot}
2
+\alias{anno_oncoprint_barplot}
3
+\title{
4
+Column barplot annotaiton for oncoPrint
5
+}
6
+\description{
7
+Column barplot annotaiton for oncoPrint
8
+}
9
+\usage{
10
+anno_oncoprint_barplot()
11
+}
12
+\details{
13
+This function is only used for column annotation
14
+}
15
+\author{
16
+Zuguang Gu <z.gu@dkfz.de>
17
+}
18
+\examples{
19
+# There is no example
20
+NULL
21
+
22
+}
... ...
@@ -41,6 +41,7 @@ There are following parameters:
41 41
   \item{heatmap_legend_grid_width}{set \code{grid_width} element in \code{legend_param} in \code{\link{SingleAnnotation}}.}
42 42
   \item{heatmap_legend_grid_height}{set \code{grid_height} element in \code{legend_param} in \code{\link{SingleAnnotation}}.}
43 43
   \item{heatmap_legend_grid_border}{set \code{grid_border} element in \code{legend_param} in \code{\link{SingleAnnotation}}.}
44
+  \item{fast_hclust}{whether use \code{\link[fastcluster]{hclust}} to speed up clustering?}
44 45
 }
45 46
 
46 47
 You can get or set option values by the traditional way (like \code{\link[base]{options}}) or by \code{$} operator:
... ...
@@ -18,7 +18,7 @@ oncoPrint(mat, get_type = function(x) x,
18 18
     row_barplot_width = unit(2, "cm"),
19 19
     remove_empty_columns = FALSE,
20 20
     heatmap_legend_param = list(title = "Alterations"),
21
-    top_annotation = HeatmapAnnotation(column_bar = anno_column_bar,
21
+    top_annotation = HeatmapAnnotation(column_bar = anno_oncoprint_barplot(),
22 22
     annotation_height = unit(2, "cm")),
23 23
     barplot_ignore = NULL,
24 24
     ...)
... ...
@@ -7,19 +7,18 @@ Construct row annotations
7 7
 Construct row annotations
8 8
 }
9 9
 \usage{
10
-rowAnnotation(..., width = unit(1, "cm"))
10
+rowAnnotation(...)
11 11
 }
12 12
 \arguments{
13 13
 
14 14
   \item{...}{pass to \code{\link{HeatmapAnnotation}}}
15
-  \item{width}{default width of the row annotations}
16 15
 
17 16
 }
18 17
 \details{
19 18
 The function is identical to
20 19
 
21 20
   \preformatted{
22
-    HeatmapAnnotation(..., which = "row", width = width)  }
21
+    HeatmapAnnotation(..., which = "row")  }
23 22
 }
24 23
 \value{
25 24
 A \code{\link{HeatmapAnnotation-class}} object.
... ...
@@ -64,7 +64,7 @@ to get full use of the package.
64 64
 
65 65
 ## Vignettes
66 66
 
67
-There are several vignettes in the package. Each vignette focuses on a specific topic. Following
67
+There are several vignettes in the package. Each vignette focuses on one specific topic. Following
68 68
 lists the general topics discussed in these vignettes:
69 69
 
70 70
   1. [**Making a Single Heatmap**](s2.single_heatmap.html)
... ...
@@ -72,13 +72,13 @@ lists the general topics discussed in these vignettes:
72 72
     This vignette introduces the basic configuration for making a single heatmap. Similar as other
73 73
     R functions/packages, the basic usage is quite similar, but there are several unique features
74 74
     for **ComplexHeamtap** package.
75
-    - Works both for numeric matrix and character matrix
75
+    - Works both for numeric matrix and character matrix.
76 76
     - For numeric matrix which contains continuous values, the package allows a color mapping function
77 77
       which can give more accurate colors and be robust to outliers.
78 78
     - Highly flexible for clustering. You can define the distance method for clustering by:
79
-          * a pre-defined distance such as "euclidean" or "pearson"
80
-          * a self-defined function which calculates distance from a matrix.
81
-          * a self-defined function which calculates distance from two vectors
79
+          * a pre-defined distance such as "euclidean" or "pearson",
80
+          * a self-defined function which calculates distance from a matrix,
81
+          * a self-defined function which calculates distance from two vectors.
82 82
         
83 83
         You can define the clustering method by:
84 84
           * a clustering function such as `diana()` from **cluster** package
... ...
@@ -96,7 +96,7 @@ lists the general topics discussed in these vignettes:
96 96
 
97 97
   3. [**Heatmap Annotations**](s4.heatmap_annotation.html)
98 98
 
99
-    This vignette introduces the concept of the heatmap annotation and demonstrate how to make simple annotations
99
+    This vignette introduces the concept of the heatmap annotation and demonstrates how to make simple annotations
100 100
     as well as complex annotations. Also, the vignette explains the difference between column annotations
101 101
     and row annotations.
102 102
 
... ...
@@ -121,4 +121,11 @@ lists the general topics discussed in these vignettes:
121 121
   8. [**Examples**](s9.examples.html)
122 122
 
123 123
     More simulated and real-world examples are shown in this vignette.
124
+
125
+In the supplementaries of [the ComplexHeatmap paper](http://bioinformatics.oxfordjournals.org/content/early/2016/05/20/bioinformatics.btw313.abstract), there are four comprehensive examples which are applied
126
+on real-world high-throughput datasets. [The examples can be found here.](http://jokergoo.github.io/supplementary/ComplexHeatmap-supplementary1-4/index.html)
127
+
128
+Also [my blog](http://jokergoo.github.io/blog.html) has some examples and tips for making better complex heatmaps.
129
+
130
+
124 131
     
... ...
@@ -196,7 +196,7 @@ Heatmap(mat, name = "foo", column_title = "I am a big column title",
196 196
     column_title_gp = gpar(fontsize = 20, fontface = "bold"))
197 197
 ```
198 198
 
199
-Roatations for titles can be set by `row_title_rot` and `column_title_rot`, but only horizontal and vertical 
199
+Rotations for titles can be set by `row_title_rot` and `column_title_rot`, but only horizontal and vertical 
200 200
 rotations are allowed.
201 201
 
202 202
 ```{r title_rotation}
... ...
@@ -212,7 +212,7 @@ contains clustering, or directly by a clustering function. It is also possible t
212 212
 your dendrograms with different colors and styles for different branches for better revealing
213 213
 structures of your data.
214 214
 
215
-First there are general settings for the clustering, e.g. whether show dendrograms, side
215
+First there are general settings for the clustering, e.g. whether do or show dendrograms, side
216 216
 of the dendrograms and size of the dendrograms.
217 217
 
218 218
 ```{r cluster_basic}
... ...
@@ -263,6 +263,7 @@ If possible distance method provided, you can also cluster a character matrix.
263 263
 
264 264
 ```{r cluster_character_matrix}
265 265
 mat_letters = matrix(sample(letters[1:4], 100, replace = TRUE), 10)
266
+# distance in th ASCII table
266 267
 dist_letters = function(x, y) {
267 268
     x = strtoi(charToRaw(paste(x, collapse = "")), base = 16)
268 269
     y = strtoi(charToRaw(paste(y, collapse = "")), base = 16)
... ...
@@ -294,8 +295,7 @@ Heatmap(mat, name = "foo", cluster_rows = as.dendrogram(diana(mat)),
294 295
 ```
295 296
 
296 297
 In the native `heatmap()` function, dendrograms on row and on column are reordered to let features with larger different
297
-separated more from each other, but according to my experience, the default reordering can not always give nice visualization.
298
-So by default the reordering for the dendrograms are turned off for `Heatmap()` function. 
298
+separated more from each other, By default the reordering for the dendrograms are turned on by `Heatmap()` as well. 
299 299
 
300 300
 Besides the default reordering method, you can first generate a dendrogram and apply other reordering
301 301
 method and then send the reordered dendrogram to `cluster_rows` argument. 
... ...
@@ -340,6 +340,26 @@ Heatmap(mat, name = "foo", cluster_rows = function(m) as.dendrogram(diana(m)),
340 340
     cluster_columns = function(m) as.dendrogram(agnes(m)))
341 341
 ```
342 342
 
343
+`fastcluster::hclust` implements a faster version of `hclust`. We can re-define `cluster_rows` and `cluster_columns`
344
+to use the faster version of `hclust`. But note `fastcluster::hclust` only speed up the calculation of the cluster while not the
345
+calculation of distance matrix.
346
+
347
+```{r}
348
+# code not run when building the vignette
349
+Heatmap(mat, name = "foo", cluster_rows = function(m) fastcluster::hclust(dist(m)),
350
+    cluster_columns = function(m) fastcluster::hclust(dist(m))) # for column cluster, m will be automatically transposed
351
+```
352
+
353
+To make it more convinient to use the faster version of `hclust` (assuming you have many heatmaps to be concatenated), it can
354
+be set as a global option:
355
+
356
+```{r}
357
+# code not run when building the vignette
358
+ht_global_opt(fast_hclust = TRUE)
359
+# now hclust from fastcluster package is used in all heatmaps
360
+Heatmap(mat, name = "foo")
361
+```
362
+
343 363
 Clustering can help to adjust order in rows and in columns. But you can still set the order manually by `row_order`
344 364
 and `column_order`. Note you need to turn off clustering
345 365
 if you want to set order manually. `row_order` and `column_order` can also be set according to matrix row names and column names if they exist.
... ...
@@ -438,6 +458,8 @@ and they want to split rows by splitting the dendrogram into k sub trees. In thi
438 458
 `split` can be specified as a single number:
439 459
 
440 460
 ```{r split_dendrogram}
461
+dend = hclust(dist(mat))
462
+dend = color_branches(dend, k = 2)
441 463
 Heatmap(mat, name = "foo", cluster_rows = dend, split = 2)
442 464
 ```
443 465
 
... ...
@@ -600,7 +622,7 @@ the file size. In `Heatmap()` function, there are four options which control how
600 622
 the raster image: `use_raster`, `raster_device`, `raster_quality`, `raster_device_param`. 
601 623
 
602 624
 You can choose graphic device (`png`, `jpeg` and `tiff`) by `raster_device`, control the quality of the raster image by `raster_quality`,
603
-and pass further parameters for a specific device by `raster_device_param`.
625
+and pass further parameters for a specific device by `raster_device_param`. [Check this web page for better demonstrations.](http://zuguang.de/blog/html/d3aa6e2b289514ecddded64a467d1961.html)
604 626
 
605 627
 ## Session info
606 628
 
... ...
@@ -31,7 +31,8 @@ options(width = 100)
31 31
 
32 32
 A list of heatmaps can improve visualization of the correspondence between multiple data sources.
33 33
 In this vignette, we will discuss configurations for making a list of heatmaps and you can
34
-see more real-world examples in the [**Examples**](s9.examples.html) vignette.
34
+see more real-world examples in the [**Examples**](s9.examples.html) vignette as well as [in the 
35
+supplementaries](http://jokergoo.github.io/supplementary/ComplexHeatmap-supplementary1-4/index.html) of [the ComplexHeatmap paper](http://bioinformatics.oxfordjournals.org/content/early/2016/05/20/bioinformatics.btw313.abstract).
35 36
 
36 37
 ## Heatmap concatenation
37 38
 
... ...
@@ -44,13 +45,18 @@ are to be combined, users can append one heatmap to the other by `+` operator.
44 45
 ```{r heatmap_list_default, fig.width = 10}
45 46
 library(ComplexHeatmap)
46 47
 
47
-mat = matrix(rnorm(80, 2), 8, 10)
48
-mat = rbind(mat, matrix(rnorm(40, -2), 4, 10))
49
-rownames(mat) = paste0("R", 1:12)
50
-colnames(mat) = paste0("C", 1:10)
48
+mat1 = matrix(rnorm(80, 2), 8, 10)
49
+mat1 = rbind(mat1, matrix(rnorm(40, -2), 4, 10))
50
+rownames(mat1) = paste0("R", 1:12)
51
+colnames(mat1) = paste0("C", 1:10)
52
+
53
+mat2 = matrix(rnorm(60, 2), 6, 10)
54
+mat2 = rbind(mat2, matrix(rnorm(60, -2), 6, 10))
55
+rownames(mat2) = paste0("R", 1:12)
56
+colnames(mat2) = paste0("C", 1:10)
51 57
 
52
-ht1 = Heatmap(mat, name = "ht1")
53
-ht2 = Heatmap(mat, name = "ht2")
58
+ht1 = Heatmap(mat1, name = "ht1")
59
+ht2 = Heatmap(mat2, name = "ht2")
54 60
 class(ht1)
55 61
 class(ht2)
56 62
 
... ...
@@ -61,7 +67,7 @@ Under default mode, dendrograms from the second heatmap will be removed and row
61 67
 
62 68
 The returned value of addition of two heatmaps is a `HeatmapList` object. Directly calling `ht_list` object
63 69
 will call `draw()` method with default settings. With explicitly calling `draw()` method, you can have more controls
64
-on the legend and titles.
70
+e.g. on the legend and titles.
65 71
 
66 72
 ```{r}
67 73
 ht_list = ht1 + ht2
... ...
@@ -91,8 +97,8 @@ for(s in sth) {
91 97
 A heatmap list also has titles which are independent to the heatmap titles.
92 98
 
93 99
 ```{r heatmap_list_title, fig.width = 10}
94
-ht1 = Heatmap(mat, name = "ht1", row_title = "Heatmap 1", column_title = "Heatmap 1")
95
-ht2 = Heatmap(mat, name = "ht2", row_title = "Heatmap 2", column_title = "Heatmap 2")
100
+ht1 = Heatmap(mat1, name = "ht1", row_title = "Heatmap 1", column_title = "Heatmap 1")
101
+ht2 = Heatmap(mat2, name = "ht2", row_title = "Heatmap 2", column_title = "Heatmap 2")
96 102
 ht_list = ht1 + ht2
97 103
 
98 104
 draw(ht_list, row_title = "Two heatmaps, row title", row_title_gp = gpar(col = "red"),
... ...
@@ -113,8 +119,8 @@ draw(ht_list + ht_list, gap = unit(c(3, 6, 9, 0), "mm"))
113 119
 The width for some (not all) heatmaps can be set to a fixed width.
114 120
 
115 121
 ```{r heatmap_list_size, fig.width = 10, fig.keep = "all"}
116
-ht1 = Heatmap(mat, name = "ht1", column_title = "Heatmap 1")
117
-ht2 = Heatmap(mat, name = "ht2", column_title = "Heatmap 2", width = unit(5, "cm"))
122
+ht1 = Heatmap(mat1, name = "ht1", column_title = "Heatmap 1")
123
+ht2 = Heatmap(mat2, name = "ht2", column_title = "Heatmap 2", width = unit(5, "cm"))
118 124
 ht1 + ht2
119 125
 ```
120 126
 
... ...
@@ -122,8 +128,8 @@ or the width can be set as relative values. Please not in this case, `width` for
122 128
 should be set (relative width and fixed width can be mixed).
123 129
 
124 130
 ```{r heatmap_list_relative_size, fig.width = 10, fig.keep = "all"}
125
-ht1 = Heatmap(mat, name = "ht1", column_title = "Heatmap 1", width = 2)
126
-ht2 = Heatmap(mat, name = "ht2", column_title = "Heatmap 2", width = 1)
131
+ht1 = Heatmap(mat1, name = "ht1", column_title = "Heatmap 1", width = 2)
132
+ht2 = Heatmap(mat2, name = "ht2", column_title = "Heatmap 2", width = 1)
127 133
 ht1 + ht2
128 134
 ```
129 135
 
... ...
@@ -141,8 +147,8 @@ The main heatmap can be specified by `main_heatmap` argument. The value can be a
141 147
 (of course, you need to set the heatmap name when you create the `Heatmap` object).
142 148
 
143 149
 ```{r heatmap_list_auto_adjust, fig.width = 10, fig.keep = "all"}
144
-ht1 = Heatmap(mat, name = "ht1", column_title = "Heatmap 1", km = 2)
145
-ht2 = Heatmap(mat, name = "ht2", column_title = "Heatmap 2")
150
+ht1 = Heatmap(mat1, name = "ht1", column_title = "Heatmap 1", km = 2)
151
+ht2 = Heatmap(mat2, name = "ht2", column_title = "Heatmap 2")
146 152
 ht1 + ht2
147 153
 
148 154
 # note we changed the order of `ht1` and `ht2`
... ...
@@ -156,8 +162,8 @@ draw(ht2 + ht1, main_heatmap = "ht1")
156 162
 If there is no row clustering in the main heatmap, all other heatmaps have no row clustering neither.
157 163
 
158 164
 ```{r heatmap_list_auto_adjust_no_row_cluster, fig.width = 10}
159
-ht1 = Heatmap(mat, name = "ht1", column_title = "Heatmap 1", cluster_rows = FALSE)
160
-ht2 = Heatmap(mat, name = "ht2", column_title = "Heatmap 2")
165
+ht1 = Heatmap(mat1, name = "ht1", column_title = "Heatmap 1", cluster_rows = FALSE)
166
+ht2 = Heatmap(mat2, name = "ht2", column_title = "Heatmap 2")
161 167
 ht1 + ht2
162 168
 ```
163 169
 
... ...
@@ -168,8 +174,8 @@ ht1 + ht2
168 174
 ```{r, fig.width = 10}
169 175
 ht_global_opt(heatmap_row_names_gp = gpar(fontface = "italic"), 
170 176
 	          heatmap_column_names_gp = gpar(fontsize = 14))
171
-ht1 = Heatmap(mat, name = "ht1", column_title = "Heatmap 1")
172
-ht2 = Heatmap(mat, name = "ht2", column_title = "Heatmap 2")
177
+ht1 = Heatmap(mat1, name = "ht1", column_title = "Heatmap 1")
178
+ht2 = Heatmap(mat2, name = "ht2", column_title = "Heatmap 2")
173 179
 ht1 + ht2
174 180
 ht_global_opt(RESET = TRUE)
175 181
 ```
... ...
@@ -208,7 +214,7 @@ column_dend(ht_list)
208 214
 
209 215
 ## Heatmap list with row annotations
210 216
 
211
-Row annotations can also be reordered and split according to the main heatmap, 
217
+Row annotations can be added to the heatmap list, 
212 218
 please see [**Heatmap Annotation**](s4.heatmap_annotation.html) for more explanations.
213 219
 
214 220
 ## Modify row orders/clustering in main heatmap
... ...
@@ -218,11 +224,7 @@ in `draw()` method. This makes it convinient to switch main heatmaps without mod
218 224
 heatmaps. Actually settings specified in `draw()` will overwrite corresponding settings in the main heatmap.
219 225
 
220 226
 ```{r, fig.width = 8}
221
-mat1 = matrix(rnorm(80, 2), 8, 10)
222
-mat1 = rbind(mat1, matrix(rnorm(40, -2), 4, 10))
223
-mat2 = mat1[sample(1:nrow(mat1)), ]
224
-
225
-split = sample(c("a", "b"), nrow(mat1), replace = TRUE)
227
+split = rep(c("a", "b"), each = 6)
226 228
 ht_list = Heatmap(mat1, name = "mat1", cluster_rows = FALSE, column_title = "mat1") + 
227 229
           Heatmap(mat2, name = "mat2", cluster_rows = FALSE, column_title = "mat2")
228 230
 draw(ht_list, main_heatmap = "mat1", split = split)
... ...
@@ -45,7 +45,7 @@ color mapping functions, depending on whether the simple annotations are discret
45 45
 In the heatmap, simple annotations will be represented as rows of grids.
46 46
 
47 47
 There is a `draw()` method for the `HeatmapAnnotation` class. `draw()` is used internally and here
48
-we just use it for illustration.
48
+we just use it for demonstration.
49 49
 
50 50
 ```{r heatmap_annotation, fig.width = 7, fig.height = 0.5}
51 51
 library(ComplexHeatmap)
... ...
@@ -103,7 +103,7 @@ ha
103 103
 draw(ha, 1:10)
104 104
 ```
105 105
 
106
-Also individual annotations can be specified as vectors:
106
+Also individual annotations can be directly specified as vectors:
107 107
 
108 108
 ```{r heatmap_annotation_vector, fig.width = 7, fig.height = 1}
109 109
 ha = HeatmapAnnotation(type = c(rep("a", 5), rep("b", 5)),
... ...
@@ -367,7 +367,7 @@ The order of elements in row annotations will be adjusted by the clustering of h
367 367
 ha = rowAnnotation(df = df, col = list(type = c("a" = "red", "b" = "blue")),
368 368
     width = unit(1, "cm"))
369 369
 ht1 = Heatmap(mat, name = "ht1")
370
-ht1 = Heatmap(mat, name = "ht2")
370
+ht2 = Heatmap(mat, name = "ht2")
371 371
 ht1 + ha + ht2
372 372
 ```
373 373
 
... ...
@@ -378,7 +378,7 @@ splitted as well.
378 378
 ht1 = Heatmap(mat, name = "ht1", km = 2)
379 379
 ha = rowAnnotation(df = df, col = list(type = c("a" = "red", "b" = "blue")),
380 380
     boxplot = row_anno_boxplot(mat, axis = TRUE), 
381
-    width = unit(6, "cm"))
381
+    annotation_width = unit(c(1, 5), "cm"))
382 382
 ha + ht1
383 383
 ```
384 384
 
... ...
@@ -544,6 +544,43 @@ draw(ht_list, column_title = "reverse axis direction", newpage = FALSE)
544 544
 upViewport(2)
545 545
 ```
546 546
 
547
+## Add annotation names
548
+
549
+From version 1.11.5, `HeatmapAnnotation()` supports adding annotation names directly to the annotations.
550
+However, due to the design of the package, sometimes the names will be positioned outside of the plot
551
+or overlap to other heatmap compoments, thus, by default it is turned off.
552
+
553
+```{r}
554
+df = data.frame(type = c(rep("a", 5), rep("b", 5)),
555
+                age = sample(1:20, 10))
556
+value = rnorm(10)
557
+ha = HeatmapAnnotation(df = df, points = anno_points(value, axis = TRUE),
558
+    col = list(type = c("a" = "red", "b" = "blue"),
559
+               age = colorRamp2(c(0, 20), c("white", "red"))),
560
+    annotation_height = unit(c(0.5, 0.5, 2), "cm"),
561
+    show_annotation_name = TRUE,
562
+    annotation_name_offset = unit(2, "mm"),
563
+    annotation_name_rot = c(0, 0, 90))
564
+Heatmap(mat, name = "foo", top_annotation = ha)
565
+```
566
+
567
+Or the row annotation names: Note we manually adjust `padding` to fully show the text of "points".
568
+
569
+```{r}
570
+df = data.frame(type = c(rep("a", 6), rep("b", 6)),
571
+                age = sample(1:20, 12))
572
+value = rnorm(12)
573
+ha = rowAnnotation(df = df, points = row_anno_points(value, axis = TRUE),
574
+    col = list(type = c("a" = "red", "b" = "blue"),
575
+               age = colorRamp2(c(0, 20), c("white", "red"))),
576
+    annotation_width = unit(c(0.5, 0.5, 2), "cm"),
577
+    show_annotation_name = c(TRUE, FALSE, TRUE),
578
+    annotation_name_offset = unit(c(2, 2, 8), "mm"),
579
+    annotation_name_rot = c(90, 90, 0))
580
+ht = Heatmap(mat, name = "foo") + ha
581
+draw(ht, padding = unit(c(4, 2, 2, 2), "mm"))
582
+```
583
+
547 584
 ## Adjust positions of column names
548 585
 
549 586
 In the layout of the heatmap components, column names are put directly below the heatmap body. This will cause
... ...
@@ -119,7 +119,8 @@ ha = HeatmapAnnotation(df = df, col = list(type = c("a" =  "red", "b" = "blue"))
119 119
                                                labels_gp = gpar(fontsize = 8))))
120 120
 ht1 = Heatmap(mat, name = "ht1", column_title = "Heatmap 1", top_annotation = ha)
121 121
 ht2 = Heatmap(mat, name = "ht2", column_title = "Heatmap 2", 
122
-    heatmap_legend_param = list(title = "Heatmap2", title_gp = gpar(fontsize = 8), labels_gp = gpar(fontsize = 14)))
122
+    heatmap_legend_param = list(title = "Heatmap2", title_gp = gpar(fontsize = 8), 
123
+        labels_gp = gpar(fontsize = 14)))
123 124
 ht1 + ht2
124 125
 ```
125 126
 
... ...
@@ -146,6 +147,16 @@ ht1 = Heatmap(mat, name = "ht1")
146 147
 ht1 + ha_chr
147 148
 ```
148 149
 
150
+Or put at bottom of the heatmap:
151
+
152
+```{r, fig.width = 6}
153
+ha_chr = rowAnnotation(chr = sample(paste0("chr", 1:20), nrow(mat), replace = TRUE),
154
+    annotation_legend_param = list(chr = list(nrow = 2, title = "chr", title_position = "leftcenter")),
155
+    width = unit(5, "mm"))
156
+ht1 = Heatmap(mat, name = "ht1", show_heatmap_legend = FALSE)
157
+draw(ht1 + ha_chr, heatmap_legend_side = "bottom")
158
+```
159
+
149 160
 If you don't like the default discrete color bar for continuous values, you can specify `color_bar` to `continuous`.
150 161
 For the simple annotation which contains continuous values, `color_bar` can also be set to `continuous`.
151 162
 
... ...
@@ -206,6 +217,8 @@ lgd = Legend(at = c("class1", "class2"), title = "points", type = "points", lege
206 217
 draw(ht, annotation_legend_list = list(lgd))
207 218
 ```
208 219
 
220
+Also check [this blog link](http://zuguang.de/blog/html/dde69a9cf5a606a9486b19eb91ba6f4e.html) for more demonstrations.
221
+
209 222
 ## Session info
210 223
 
211 224
 ```{r}
... ...
@@ -165,7 +165,8 @@ can be used in the decoration code.
165 165
 
166 166
 By default, annotation names are not plotted along with the heatmap annotations. The reason is
167 167
 if annotation names is plotted, they will located in the area of other heatmap components which
168
-would makes the adjustment of the heatmap layout difficult. But since you can go to any component 
168
+would makes the adjustment of the heatmap layout difficult. `HeatmapAnnotation()` provides a 
169
+not-so-perfect [solution](s4.heatmap_annotation.html#toc_11) for adding annotation names, however, since you can go to any component 
169 170
 in the heatmap list by its name, actually it is not difficult to add annotation names manually.
170 171
 
171 172
 Following code add annotation names on the both sides of the column annotations. The drawback is
... ...
@@ -37,16 +37,18 @@ additional barplots at both sides of the heatmap which show numbers of different
37 37
 each sample and for each gene. Also with the functionality of **ComplexHeatmap**, you can control oncoPrint with
38 38
 more flexibilities.
39 39
 
40
+## General settings
41
+
40 42
 There are two different forms of input data. The first is represented as a matrix in which 
41 43
 element would include multiple alterations in a form of a complex string. In follow example,
42 44
 'g1' in 's1' has two types of alterations which are 'snv' and 'indel'.
43 45
 
44 46
 ```{r}
45 47
 mat = read.table(textConnection(
46
-"	s1	s2	s3
47
-g1	snv;indel	snv	indel
48
-g2		snv;indel	snv
49
-g3	snv		indel;snv"), row.names = 1, header = TRUE, sep = "\t", stringsAsFactors = FALSE)
48
+",s1,s2,s3
49
+g1,snv;indel,snv,indel
50
+g2,,snv;indel,snv
51
+g3,snv,,indel;snv"), row.names = 1, header = TRUE, sep = ",", stringsAsFactors = FALSE)
50 52
 mat = as.matrix(mat)
51 53
 mat
52 54
 ```
... ...
@@ -78,7 +80,10 @@ oncoPrint(mat, get_type = function(x) strsplit(x, ";")[[1]],
78 80
 	), col = col)
79 81
 ```
80 82
 
81
-The second type of input data is a list of matrix for which each matrix contains binary value representing
83
+In above example, form of the string (e.g. `snv;indel`) correlates to how you define `get_type`. If the string
84
+has the form of `snv|indel|amp`, `get_type` should be defined as `function(x) strsplit(x, "|")[[1]]`.
85
+
86
+If you are pulzzed by how to generated the matrix, there is a second way. The second type of input data is a list of matrix for which each matrix contains binary value representing
82 87
 whether the alteration is absent or present. The list should have names which correspond to the alteration
83 88
 types.
84 89
 
... ...
@@ -94,36 +99,34 @@ mat_list
94 99
 to adjust the matrix list.
95 100
 
96 101
 ```{r}
97
-mat_list$indel = mat_list$indel[1:2, 1:2]
98
-mat_list
99
-mat_list = unify_mat_list(mat_list)
100
-mat_list
102
+mat_list2 = mat_list
103
+mat_list2$indel = mat_list2$indel[1:2, 1:2]
104
+mat_list2
105
+mat_list2 = unify_mat_list(mat_list2)
106
+mat_list2
101 107
 ```
102 108
 
103
-Same as the first example, but here we also define `background` in `alter_fun` argument. This function defines
104
-how to add graphics when there is no alteration and it is always put as the first in the list.
109
+Pass `mat_list` to `oncoPrint()`:
105 110
 
106 111
 ```{r}
107 112
 oncoPrint(mat_list,
108 113
 	alter_fun = list(
109
-		background = function(x, y, w, h) NULL,
110 114
 		snv = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.9, gp = gpar(fill = col["snv"], col = NA)),
111 115
 		indel = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.4, gp = gpar(fill = col["indel"], col = NA))
112 116
 	), col = col)
113 117
 ```
114 118
 
115
-If types of alterations is less than two and the purpose is only to have a quick look at the data, there are default
116
-graphics added:
117
-
118
-```{r}
119
-oncoPrint(mat_list)
120
-```
121
-
122 119
 In above examples, `alter_fun` is a list of functons which add graphics layer by layer. Graphics
123 120
 can also be added in a grid-by-grid style by specifying `alter_fun` as a single function. The difference
124 121
 from the function list is now `alter_fun` should accept a fifth argument which is a logical vector. 
125 122
 This logical vector shows whether different alterations exist for current gene in current sample.
126 123
 
124
+Let's assume in a grid there is only snv event, `v` for this grid is:
125
+
126
+```{r, echo = FALSE}
127
+print(c("snv" = TRUE, "indel" = FALSE))
128
+```
129
+
127 130
 ```{r}
128 131
 oncoPrint(mat_list,
129 132
 	alter_fun = function(x, y, w, h, v) {
... ...
@@ -146,6 +149,32 @@ oncoPrint(mat_list,
146 149
     }, col = col)
147 150
 ```
148 151
 
152
+If `alter_fun` is specified as a list, the order of the elements controls the order of adding graphics. 
153
+There is a special element named `background` which defines how to draw background and it should be always put
154
+as the first element in the `alter_fun` list. In following example, backgrond color is changed to light green with borders.
155
+
156
+```{r}
157
+oncoPrint(mat_list,
158
+	alter_fun = list(
159
+		background = function(x, y, w, h) grid.rect(x, y, w, h, gp = gpar(fill = "#00FF0020")),
160
+		snv = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.9, gp = gpar(fill = col["snv"], col = NA)),
161
+		indel = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.4, gp = gpar(fill = col["indel"], col = NA))
162
+	), col = col)
163
+```
164
+
165
+Or just remove the background:
166
+
167
+```{r}
168
+oncoPrint(mat_list,
169
+	alter_fun = list(
170
+		background = NULL,
171
+		snv = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.9, gp = gpar(fill = col["snv"], col = NA)),
172
+		indel = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.4, gp = gpar(fill = col["indel"], col = NA))
173
+	), col = col)
174
+```
175
+
176
+## Apply to cBioPortal dataset
177
+
149 178
 Now we make an oncoPrint with a real-world data. The data is retrieved from [cBioPortal](http://www.cbioportal.org/). 
150 179
 Steps for getting the data are as follows:
151 180
 
... ...
@@ -264,7 +293,7 @@ ht_list = oncoPrint(mat, get_type = function(x) strsplit(x, ";")[[1]],
264 293
 	heatmap_legend_param = list(title = "Alternations", at = c("AMP", "HOMDEL", "MUT"), 
265 294
 		labels = c("Amplification", "Deep deletion", "Mutation")),
266 295
 	split = sample(letters[1:2], nrow(mat), replace = TRUE)) +
267
-Heatmap(matrix(rnorm(nrow(mat)*10), ncol = 10), name = "expr", width = unit(4, "cm"))
296
+Heatmap(matrix(rnorm(nrow(mat)*10), ncol = 10), name = "expr", show_column_dend = FALSE, width = unit(4, "cm"))
268 297
 draw(ht_list, row_sub_title_side = "left")
269 298
 ```
270 299
 
... ...
@@ -28,6 +28,11 @@ options(markdown.HTML.stylesheet = "custom.css")
28 28
 options(width = 100)
29 29
 ```
30 30
 
31
+In the supplementaries of [the ComplexHeatmap paper](http://bioinformatics.oxfordjournals.org/content/early/2016/05/20/bioinformatics.btw313.abstract), there are four comprehensive examples which are applied
32
+on real-world high-throughput datasets. [The examples can be found here.](http://jokergoo.github.io/supplementary/ComplexHeatmap-supplementary1-4/index.html)
33
+
34
+Also [my blog](http://jokergoo.github.io/blog.html) has some examples and tips for making better complex heatmaps.
35
+
31 36
 
32 37
 ### Add more information for gene expression matrix
33 38