Browse code

R CMD check passed

Zuguang Gu authored on 20/09/2018 12:48:08
Showing225 changed files

... ...
@@ -1,7 +1,9 @@
1 1
 ^\..*
2 2
 README.*
3
-test/
3
+tests/
4 4
 check.bat
5 5
 ^.*\.Rproj$
6 6
 ^\.Rproj\.user$
7 7
 .travis.yml
8
+vignettes_old
9
+
... ...
@@ -1,7 +1,7 @@
1 1
 Package: ComplexHeatmap
2 2
 Type: Package
3 3
 Title: Making Complex Heatmaps
4
-Version: 1.19.1
4
+Version: 1.99.0
5 5
 Date: 2018-6-9
6 6
 Author: Zuguang Gu
7 7
 Maintainer: Zuguang Gu <z.gu@dkfz.de>
... ...
@@ -10,7 +10,7 @@ Imports: circlize (>= 0.4.1), GetoptLong, colorspace,
10 10
     RColorBrewer, GlobalOptions (>= 0.1.0)
11 11
 Suggests: testthat (>= 0.3), knitr, markdown, cluster, MASS, pvclust, 
12 12
     dendsort, HilbertCurve, Cairo, png, jpeg, tiff, fastcluster,
13
-    dendextend (>= 1.0.1)
13
+    dendextend (>= 1.0.1), grImport, grImport2, rsvg
14 14
 VignetteBuilder: knitr
15 15
 Description: Complex heatmaps are efficient to visualize associations 
16 16
     between different sources of data sets and reveal potential structures. 
... ...
@@ -1,100 +1,197 @@
1
-export('+.AdditiveUnit')
2
-export('grid.dendrogram')
3
-export('grid.dendrogram2')
4
-export(AdditiveUnit)
5
-export(ColorMapping)
6
-export(Heatmap)
7
-export(HeatmapAnnotation)
8
-export(HeatmapList)
9
-export(Legend)
10
-export(SingleAnnotation)
11
-export(adjust_dend_by_leaf_width)
12
-export(anno_barplot)
13
-export(anno_boxplot)
14
-export(anno_density)
15
-export(anno_histogram)
16
-export(anno_link)
17
-export(anno_oncoprint_barplot)
18
-export(anno_points)
19
-export(anno_text)
20
-export(columnAnnotation)
21
-export(column_anno_barplot)
22
-export(column_anno_boxplot)
23
-export(column_anno_density)
24
-export(column_anno_histogram)
25
-export(column_anno_link)
26
-export(column_anno_points)
27
-export(column_anno_text)
28
-export(decorate_annotation)
29
-export(decorate_column_dend)
30
-export(decorate_column_names)
31
-export(decorate_column_title)
32
-export(decorate_dend)
33
-export(decorate_dimnames)
34
-export(decorate_heatmap_body)
35
-export(decorate_row_dend)
36
-export(decorate_row_names)
37
-export(decorate_row_title)
38
-export(decorate_title)
39
-export(densityHeatmap)
40
-export(dist2)
41
-export(enhanced_basicplot)
42
-export(ht_global_opt)
43
-export(is_abs_unit)
44
-export(max_text_height)
45
-export(max_text_width)
46
-export(oncoPrint)
47
-export(packLegend)
48
-export(plotDataFrame)
49
-export(rowAnnotation)
50
-export(row_anno_barplot)
51
-export(row_anno_boxplot)
52
-export(row_anno_density)
53
-export(row_anno_histogram)
54
-export(row_anno_link)
55
-export(row_anno_points)
56
-export(row_anno_text)
57
-export(selectArea)
58
-export(unify_mat_list)
59
-exportClasses(AdditiveUnit)
60
-export(AdditiveUnit)
61
-exportClasses(ColorMapping)
62
-export(ColorMapping)
63
-exportClasses(Heatmap)
64
-export(Heatmap)
65
-exportClasses(HeatmapAnnotation)
66
-export(HeatmapAnnotation)
67
-exportClasses(HeatmapList)
68
-export(HeatmapList)
69
-exportClasses(SingleAnnotation)
70
-export(SingleAnnotation)
71
-exportMethods(add_heatmap)
72
-exportMethods(annotation_legend_size)
73
-exportMethods(color_mapping_legend)
74
-exportMethods(column_dend)
75
-exportMethods(column_order)
76
-exportMethods(component_height)
77
-exportMethods(component_width)
78
-exportMethods(draw)
79
-exportMethods(draw_annotation)
80
-exportMethods(draw_annotation_legend)
81
-exportMethods(draw_dend)
82
-exportMethods(draw_dimnames)
83
-exportMethods(draw_heatmap_body)
84
-exportMethods(draw_heatmap_legend)
85
-exportMethods(draw_heatmap_list)
86
-exportMethods(draw_title)
87
-exportMethods(get_color_mapping_list)
88
-exportMethods(get_color_mapping_param_list)
89
-exportMethods(heatmap_legend_size)
90
-exportMethods(make_column_cluster)
91
-exportMethods(make_layout)
92
-exportMethods(make_row_cluster)
93
-exportMethods(map_to_colors)
94
-exportMethods(prepare)
95
-exportMethods(row_dend)
96
-exportMethods(row_order)
97
-exportMethods(set_component_height)
1
+S3method("+", "AdditiveUnit")
2
+export("+.AdditiveUnit")
3
+S3method("[", "AnnotationFunction")
4
+export("[.AnnotationFunction")
5
+S3method("[", "Heatmap")
6
+export("[.Heatmap")
7
+S3method("[", "HeatmapAnnotation")
8
+export("[.HeatmapAnnotation")
9
+S3method("[", "SingleAnnotation")
10
+export("[.SingleAnnotation")
11
+S3method("c", "HeatmapAnnotation")
12
+export("c.HeatmapAnnotation")
13
+S3method("dim", "Heatmap")
14
+export("dim.Heatmap")
15
+S3method("grid.draw", "Legends")
16
+export("grid.draw.Legends")
17
+S3method("height", "AnnotationFunction")
18
+export("height.AnnotationFunction")
19
+S3method("height", "HeatmapAnnotation")
20
+export("height.HeatmapAnnotation")
21
+S3method("height", "Legends")
22
+export("height.Legends")
23
+S3method("height", "SingleAnnotation")
24
+export("height.SingleAnnotation")
25
+S3method("height<-", "AnnotationFunction")
26
+export("height<-.AnnotationFunction")
27
+S3method("height<-", "HeatmapAnnotation")
28
+export("height<-.HeatmapAnnotation")
29
+S3method("height<-", "SingleAnnotation")
30
+export("height<-.SingleAnnotation")
31
+S3method("length", "HeatmapAnnotation")
32
+export("length.HeatmapAnnotation")
33
+S3method("merge", "dendrogram")
34
+export("merge.dendrogram")
35
+S3method("names", "HeatmapAnnotation")
36
+export("names.HeatmapAnnotation")
37
+S3method("names<-", "HeatmapAnnotation")
38
+export("names<-.HeatmapAnnotation")
39
+S3method("ncol", "Heatmap")
40
+export("ncol.Heatmap")
41
+S3method("nobs", "AnnotationFunction")
42
+export("nobs.AnnotationFunction")
43
+S3method("nobs", "HeatmapAnnotation")
44
+export("nobs.HeatmapAnnotation")
45
+S3method("nobs", "SingleAnnotation")
46
+export("nobs.SingleAnnotation")
47
+S3method("nrow", "Heatmap")
48
+export("nrow.Heatmap")
49
+S3method("size", "AnnotationFunction")
50
+export("size.AnnotationFunction")
51
+S3method("size", "HeatmapAnnotation")
52
+export("size.HeatmapAnnotation")
53
+S3method("size", "SingleAnnotation")
54
+export("size.SingleAnnotation")
55
+S3method("size<-", "AnnotationFunction")
56
+export("size<-.AnnotationFunction")
57
+S3method("size<-", "HeatmapAnnotation")
58
+export("size<-.HeatmapAnnotation")
59
+S3method("size<-", "SingleAnnotation")
60
+export("size<-.SingleAnnotation")
61
+S3method("summary", "Heatmap")
62
+export("summary.Heatmap")
63
+S3method("width", "AnnotationFunction")
64
+export("width.AnnotationFunction")
65
+S3method("width", "HeatmapAnnotation")
66
+export("width.HeatmapAnnotation")
67
+S3method("width", "Legends")
68
+export("width.Legends")
69
+S3method("width", "SingleAnnotation")
70
+export("width.SingleAnnotation")
71
+S3method("width<-", "AnnotationFunction")
72
+export("width<-.AnnotationFunction")
73
+S3method("width<-", "HeatmapAnnotation")
74
+export("width<-.HeatmapAnnotation")
75
+S3method("width<-", "SingleAnnotation")
76
+export("width<-.SingleAnnotation")
77
+export("%v%")
78
+export("AdditiveUnit")
79
+export("AnnotationFunction")
80
+export("ColorMapping")
81
+export("Heatmap")
82
+export("HeatmapAnnotation")
83
+export("HeatmapList")
84
+export("Legend")
85
+export("Legends")
86
+export("SingleAnnotation")
87
+export("adjust_dend_by_x")
88
+export("anno_barplot")
89
+export("anno_boxplot")
90
+export("anno_density")
91
+export("anno_empty")
92
+export("anno_histogram")
93
+export("anno_horizon")
94
+export("anno_image")
95
+export("anno_joyplot")
96
+export("anno_lines")
97
+export("anno_link")
98
+export("anno_mark")
99
+export("anno_oncoprint_barplot")
100
+export("anno_points")
101
+export("anno_simple")
102
+export("anno_text")
103
+export("cluster_within_group")
104
+export("columnAnnotation")
105
+export("decorate_annotation")
106
+export("decorate_column_dend")
107
+export("decorate_column_names")
108
+export("decorate_column_title")
109
+export("decorate_dend")
110
+export("decorate_dimnames")
111
+export("decorate_heatmap_body")
112
+export("decorate_row_dend")
113
+export("decorate_row_names")
114
+export("decorate_row_title")
115
+export("decorate_title")
116
+export("default_axis_param")
117
+export("dend_heights")
118
+export("dend_xy")
119
+export("dendrogramGrob")
120
+export("densityHeatmap")
121
+export("dist2")
122
+export("grid.dendrogram")
123
+export("height")
124
+export("height<-")
125
+export("ht_global_opt")
126
+export("ht_opt")
127
+export("is_abs_unit")
128
+export("max_text_height")
129
+export("max_text_width")
130
+export("oncoPrint")
131
+export("packLegend")
132
+export("rowAnnotation")
133
+export("row_anno_barplot")
134
+export("row_anno_boxplot")
135
+export("row_anno_density")
136
+export("row_anno_histogram")
137
+export("row_anno_link")
138
+export("row_anno_points")
139
+export("row_anno_text")
140
+export("size")
141
+export("size<-")
142
+export("subset_gp")
143
+export("subset_matrix_by_row")
144
+export("subset_vector")
145
+export("unify_mat_list")
146
+export("width")
147
+export("width<-")
148
+exportClasses("AdditiveUnit")
149
+export("AdditiveUnit")
150
+exportClasses("AnnotationFunction")
151
+export("AnnotationFunction")
152
+exportClasses("ColorMapping")
153
+export("ColorMapping")
154
+exportClasses("Heatmap")
155
+export("Heatmap")
156
+exportClasses("HeatmapAnnotation")
157
+export("HeatmapAnnotation")
158
+exportClasses("HeatmapList")
159
+export("HeatmapList")
160
+exportClasses("Legends")
161
+export("Legends")
162
+exportClasses("SingleAnnotation")
163
+export("SingleAnnotation")
164
+exportMethods("add_heatmap")
165
+exportMethods("adjust_heatmap_list")
166
+exportMethods("annotation_legend_size")
167
+exportMethods("color_mapping_legend")
168
+exportMethods("column_dend")
169
+exportMethods("column_order")
170
+exportMethods("component_height")
171
+exportMethods("component_width")
172
+exportMethods("copy_all")
173
+exportMethods("draw")
174
+exportMethods("draw_annotation")
175
+exportMethods("draw_annotation_legend")
176
+exportMethods("draw_dend")
177
+exportMethods("draw_dimnames")
178
+exportMethods("draw_heatmap_body")
179
+exportMethods("draw_heatmap_legend")
180
+exportMethods("draw_heatmap_list")
181
+exportMethods("draw_title")
182
+exportMethods("get_color_mapping_list")
183
+exportMethods("get_legend_param_list")
184
+exportMethods("heatmap_legend_size")
185
+exportMethods("make_column_cluster")
186
+exportMethods("make_layout")
187
+exportMethods("make_row_cluster")
188
+exportMethods("map_to_colors")
189
+exportMethods("prepare")
190
+exportMethods("resize")
191
+exportMethods("row_dend")
192
+exportMethods("row_order")
193
+exportMethods("set_component_height")
194
+exportMethods("set_component_width")
98 195
 
99 196
 import(grDevices)
100 197
 import(graphics)
... ...
@@ -106,6 +203,7 @@ importFrom("GetoptLong", qq.options)
106 203
 importFrom("GetoptLong", qqcat)
107 204
 importFrom("GlobalOptions", setGlobalOptions)
108 205
 importFrom("RColorBrewer", brewer.pal)
206
+importFrom("circlize", add_transparency)
109 207
 importFrom("circlize", colorRamp2)
110 208
 importFrom("circlize", rand_color)
111 209
 importFrom("circlize", smartAlign)
... ...
@@ -113,4 +211,5 @@ importFrom("colorspace", diverge_hcl)
113 211
 importFrom("colorspace", rainbow_hcl)
114 212
 importFrom("utils", "getFromNamespace")
115 213
 importFrom("utils", "packageDescription")
214
+importFrom("utils", "str")
116 215
 
... ...
@@ -1,66 +1,31 @@
1
-
2
-setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
3
-
4 1
 setGeneric('map_to_colors', function(object, ...) standardGeneric('map_to_colors'))
5
-
6 2
 setGeneric('set_component_height', function(object, ...) standardGeneric('set_component_height'))
7
-setGeneric('set_component_width', function(object, ...) standardGeneric('set_component_width'))
8
-
9 3
 setGeneric('draw_heatmap_body', function(object, ...) standardGeneric('draw_heatmap_body'))
10
-
11
-setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
12
-
13
-setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
14
-
15 4
 setGeneric('component_height', function(object, ...) standardGeneric('component_height'))
16
-
17 5
 setGeneric('make_layout', function(object, ...) standardGeneric('make_layout'))
18
-
19
-setGeneric('draw_heatmap_legend', function(object, ...) standardGeneric('draw_heatmap_legend'))
20
-
21 6
 setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
22
-
7
+setGeneric('get_legend_param_list', function(object, ...) standardGeneric('get_legend_param_list'))
8
+setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
9
+setGeneric('make_column_cluster', function(object, ...) standardGeneric('make_column_cluster'))
10
+setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
11
+setGeneric('resize', function(object, ...) standardGeneric('resize'))
12
+setGeneric('row_order', function(object, ...) standardGeneric('row_order'))
13
+setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
14
+setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
15
+setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
16
+setGeneric('set_component_width', function(object, ...) standardGeneric('set_component_width'))
17
+setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
18
+setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
19
+setGeneric('draw_heatmap_legend', function(object, ...) standardGeneric('draw_heatmap_legend'))
23 20
 setGeneric('annotation_legend_size', function(object, ...) standardGeneric('annotation_legend_size'))
24
-
25
-setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
26
-
27 21
 setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
28
-
29
-setGeneric('get_legend_param_list', function(object, ...) standardGeneric('get_legend_param_list'))
30
-
22
+setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
31 23
 setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
32
-
33
-setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
34
-
35 24
 setGeneric('draw', function(object, ...) standardGeneric('draw'))
36
-
37
-setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
38
-
39 25
 setGeneric('draw_title', function(object, ...) standardGeneric('draw_title'))
40
-
41
-setGeneric('make_column_cluster', function(object, ...) standardGeneric('make_column_cluster'))
42
-
26
+setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
43 27
 setGeneric('component_width', function(object, ...) standardGeneric('component_width'))
44
-
45
-setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
46
-
47 28
 setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_color_mapping_list'))
48
-
49
-setGeneric('row_order', function(object, ...) standardGeneric('row_order'))
50
-
51 29
 setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
52
-
53
-setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
54
-
55
-setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
56
-
57
-setGeneric('copy_all', function(object, ...) standardGeneric('copy_all'))
58
-setGeneric('resize', function(object, ...) standardGeneric('resize'))
59 30
 setGeneric('adjust_heatmap_list', function(object, ...) standardGeneric('adjust_heatmap_list'))
60
-setGeneric('width', function(object, ...) standardGeneric('width'))
61
-setGeneric('height', function(object, ...) standardGeneric('height'))
62
-setGeneric('size', function(object, ...) standardGeneric('size'))
63
-setGeneric('width<-', function(object, value, ...) standardGeneric('width<-'))
64
-setGeneric('height<-', function(object, value, ...) standardGeneric('height<-'))
65
-setGeneric('size<-', function(object, value, ...) standardGeneric('size<-'))
66
-
31
+setGeneric('copy_all', function(object, ...) standardGeneric('copy_all'))
67 32
new file mode 100644
... ...
@@ -0,0 +1,404 @@
1
+
2
+# == title
3
+# Generic method for width
4
+#
5
+# == param
6
+# -x x
7
+# -... other arguments
8
+#
9
+width = function (x, ...) {
10
+	UseMethod("width", x)
11
+}
12
+
13
+# == title
14
+# Generic method for height
15
+#
16
+# == param
17
+# -x x
18
+# -... other arguments
19
+#
20
+height = function (x, ...) {
21
+	UseMethod("height", x)
22
+}
23
+
24
+# == title
25
+# Generic method for size
26
+#
27
+# == param
28
+# -x x
29
+# -... other arguments
30
+#
31
+size = function (x, ...) {
32
+	UseMethod("size", x)
33
+}
34
+
35
+# == title
36
+# Generic assignment method for width
37
+#
38
+# == param
39
+# -x x
40
+# -value value
41
+# -... other arguments
42
+#
43
+"width<-" = function (x, ..., value) {
44
+	UseMethod("width<-", x)
45
+}
46
+
47
+# == title
48
+# Generic assignment method for height
49
+#
50
+# == param
51
+# -x x
52
+# -value value
53
+# -... other arguments
54
+#
55
+"height<-" = function (x, ..., value) {
56
+	UseMethod("height<-", x)
57
+}
58
+
59
+# == title
60
+# Generic assignment method for size
61
+#
62
+# == param
63
+# -x x
64
+# -value value
65
+# -... other arguments
66
+#
67
+"size<-" = function (x, ..., value) {
68
+	UseMethod("size<-", x)
69
+}
70
+
71
+# == title
72
+# Width of the AnnotationFunction x
73
+#
74
+# == param
75
+# -x The `AnnotationFunction-class` x.
76
+# -... other arguments
77
+#
78
+# == example
79
+# anno = anno_points(1:10)
80
+# width(anno)
81
+# anno = anno_points(1:10, which = "row")
82
+# width(anno)
83
+width.AnnotationFunction = function(x, ...) {
84
+	x@width
85
+}
86
+
87
+# == title
88
+# Assign the Width to the AnnotationFunction x
89
+#
90
+# == param
91
+# -x The `AnnotationFunction-class` x.
92
+# -value A `grid::unit` x.
93
+# -... other arguments
94
+#
95
+"width<-.AnnotationFunction" = function(x, ..., value) {
96
+	x@width = value
97
+	x
98
+}
99
+
100
+# == title
101
+# Height of the AnnotationFunction x
102
+#
103
+# == param
104
+# -x The `AnnotationFunction-class` x.
105
+# -... other arguments
106
+#
107
+# == example
108
+# anno = anno_points(1:10)
109
+# height(anno)
110
+# anno = anno_points(1:10, which = "row")
111
+# height(anno)
112
+height.AnnotationFunction = function(x, ...) {
113
+	x@height
114
+}
115
+
116
+# == title
117
+# Assign the Height to the AnnotationFunction x
118
+#
119
+# == param
120
+# -x The `AnnotationFunction-class` x.
121
+# -value A `grid::unit` x.
122
+# -... other arguments
123
+#
124
+"height<-.AnnotationFunction" = function(x, ..., value) {
125
+	x@height = value
126
+	x
127
+}
128
+
129
+# == title
130
+# Size of the AnnotationFunction x
131
+#
132
+# == param
133
+# -x The `AnnotationFunction-class` x.
134
+# -... other arguments
135
+#
136
+# == detail
137
+# It returns the width if it is a row annotation and the height if it is a column annotation.
138
+#
139
+# == example
140
+# anno = anno_points(1:10)
141
+# size(anno)
142
+# anno = anno_points(1:10, which = "row")
143
+# size(anno)
144
+size.AnnotationFunction = function(x, ...) {
145
+	if(x@which == "row") {
146
+		x@width
147
+	} else {
148
+		x@height
149
+	}
150
+}
151
+
152
+# == title
153
+# Assign the Size to the AnnotationFunction x
154
+#
155
+# == param
156
+# -x The `AnnotationFunction-class` x.
157
+# -value A `grid::unit` x.
158
+# -... other arguments
159
+#
160
+# == detail
161
+# It assigns the width if it is a row annotation and the height if it is a column annotation.
162
+#
163
+# == example
164
+# anno = anno_points(1:10)
165
+# size(anno) = unit(4, "cm")
166
+# size(anno)
167
+"size<-.AnnotationFunction" = function(x, ..., value) {
168
+	if(x@which == "row") {
169
+		x@width = value
170
+	} else {
171
+		x@height = value
172
+	}
173
+	x
174
+}
175
+
176
+
177
+
178
+# == title
179
+# Width of the SingleAnnotation x
180
+#
181
+# == param
182
+# -x The `SingleAnnotation-class` x.
183
+# -... other arguments
184
+#
185
+width.SingleAnnotation = function(x, ...) {
186
+    x@width
187
+}
188
+
189
+# == title
190
+# Assign the Width to the SingleAnnotation x
191
+#
192
+# == param
193
+# -x The `SingleAnnotation-class` x.
194
+# -value A `grid::unit` x.
195
+# -... other arguments
196
+#
197
+"width<-.SingleAnnotation" = function(x, ..., value) {
198
+    x@width = value
199
+    if(inherits(x@fun, "AnnotationFunction")) {
200
+        width(x@fun) = value
201
+    }
202
+    x
203
+}
204
+
205
+# == title
206
+# Height of the SingleAnnotation x
207
+#
208
+# == param
209
+# -x The `SingleAnnotation-class` x.
210
+# -... other arguments
211
+#
212
+height.SingleAnnotation = function(x, ...) {
213
+    x@height
214
+}
215
+
216
+# == title
217
+# Assign the Height to the SingleAnnotation x
218
+#
219
+# == param
220
+# -x The `SingleAnnotation-class` x.
221
+# -value A `grid::unit` x.
222
+# -... other arguments
223
+#
224
+"height<-.SingleAnnotation" = function(x, ..., value) {
225
+    x@height = value
226
+    if(inherits(x@fun, "AnnotationFunction")) {
227
+        height(x@fun) = value
228
+    }
229
+    x
230
+}
231
+
232
+# == title
233
+# Size of the SingleAnnotation x
234
+#
235
+# == param
236
+# -x The `SingleAnnotation-class` x.
237
+# -... other arguments
238
+#
239
+# == detail
240
+# It returns the width if it is a row annotation and the height if it is a column annotation.
241
+#
242
+size.SingleAnnotation = function(x, ...) {
243
+    if(x@which == "row") {
244
+        x@width
245
+    } else {
246
+        x@height
247
+    }
248
+}
249
+
250
+# == title
251
+# Assign the Size of the SingleAnnotation x
252
+#
253
+# == param
254
+# -x The `SingleAnnotation-class` x.
255
+# -value A `grid::unit` x.
256
+# -... other arguments
257
+#
258
+# == detail
259
+# It assigns the width if it is a row annotation and the height if it is a column annotation.
260
+#
261
+"size<-.SingleAnnotation" = function(x, ..., value) {
262
+    if(x@which == "row") {
263
+        width(x) = value
264
+    } else {
265
+        height(x) = value
266
+    }
267
+    x
268
+}
269
+
270
+
271
+
272
+# == title
273
+# Width of the HeatmapAnnotation x
274
+#
275
+# == param
276
+# -x The `HeatmapAnnotation-class` x.
277
+# -... other arguments
278
+#
279
+width.HeatmapAnnotation = function(x, ...) {
280
+    x@width
281
+}
282
+
283
+# == title
284
+# Assign the Width to the HeatmapAnnotation x
285
+#
286
+# == param
287
+# -x The `HeatmapAnnotation-class` x.
288
+# -value A `grid::unit` x.
289
+# -... other arguments
290
+#
291
+"width<-.HeatmapAnnotation" = function(x, ..., value) {
292
+
293
+    if(x@which == "column") {
294
+    	x@width = value
295
+    	for(i in seq_along(x@anno_list)) {
296
+    		width(x@anno_list[[i]]) = value
297
+    	}
298
+    } else {
299
+    	x = resize(x, width = value)
300
+    }
301
+    x
302
+}
303
+
304
+
305
+# == title
306
+# Height of the HeatmapAnnotation x
307
+#
308
+# == param
309
+# -x The `HeatmapAnnotation-class` x.
310
+# -... other arguments
311
+#
312
+height.HeatmapAnnotation = function(x, ...) {
313
+    x@height
314
+}
315
+
316
+# == title
317
+# Assign the Height to the HeatmapAnnotation x
318
+#
319
+# == param
320
+# -x The `HeatmapAnnotation-class` x.
321
+# -value A `grid::unit` x.
322
+# -... other arguments
323
+#
324
+"height<-.HeatmapAnnotation" = function(x, ..., value) {
325
+
326
+    if(x@which == "row") {
327
+    	x@height = value
328
+    	for(i in seq_along(x@anno_list)) {
329
+    		height(x@anno_list[[i]]) = height
330
+    	}
331
+    } else {
332
+    	x = resize(x, height = value)
333
+    }
334
+    x
335
+}
336
+
337
+# == title
338
+# Size of the HeatmapAnnotation x
339
+#
340
+# == param
341
+# -x The `HeatmapAnnotation-class` x.
342
+# -... other arguments
343
+#
344
+# == detail
345
+# It returns the width if it is a row annotation and the height if it is a column annotation.
346
+#
347
+size.HeatmapAnnotation = function(x, ...) {
348
+    if(x@which == "row") {
349
+        x@width
350
+    } else {
351
+        x@height
352
+    }
353
+}
354
+
355
+# == title
356
+# Assign the Size to the HeatmapAnnotation x
357
+#
358
+# == param
359
+# -x The `HeatmapAnnotation-class` x.
360
+# -value A `grid::unit` x.
361
+# -... other arguments
362
+#
363
+# == detail
364
+# It assigns the width if it is a row annotation and the height if it is a column annotation.
365
+#
366
+"size<-.HeatmapAnnotation" = function(x, ..., value) {
367
+    if(x@which == "row") {
368
+        width(x) = value
369
+    } else {
370
+        height(x) = value
371
+    }
372
+    x
373
+}
374
+
375
+
376
+
377
+# == title
378
+# Width of the Legends
379
+#
380
+# == param
381
+# -x The `grid::grob` x returned by `Legend` or `packLegend`.
382
+# -... other arguments
383
+#
384
+# == value
385
+# The returned unit x is in ``mm``.
386
+#
387
+width.Legends = function(x, ...) {
388
+	attr(x@grob, "width")
389
+}
390
+
391
+# == title
392
+# Height of the Legends
393
+#
394
+# == param
395
+# -x The `grid::grob` x returned by `Legend` or `packLegend`.
396
+# -... other arguments
397
+#
398
+# == value
399
+# The returned unit x is in ``mm``.
400
+#
401
+height.Legends = function(x, ...) {
402
+	attr(x@grob, "height")
403
+}
404
+
... ...
@@ -45,7 +45,7 @@ AdditiveUnit = function(...) {
45 45
 # A `HeatmapList-class` object.
46 46
 #
47 47
 # == seealso
48
-# `%v%` operator is used for vertical heatmap list.
48
+# `\%v\%` operator is used for vertical heatmap list.
49 49
 #
50 50
 # == author
51 51
 # Zuguang Gu <z.gu@dkfz.de>
... ...
@@ -1,10 +1,17 @@
1 1
 
2 2
 # == title
3
-# AnnotationFunction class
3
+# The AnnotationFunction class
4 4
 #
5 5
 # == details
6
-# THe AnnotationFunction class is a wrapper of user-defined annotation functions.
7
-# See `AnnotationFunction` constructor for details
6
+# The heatmap annotation is basically graphics aligned to the columns or heatmap if it is column annotation
7
+# or heatmap rows if it is row annotation, while the type of the graphics can be arbitory, e.g.
8
+# it can be heatmap-like or points. Here the AnnotationFunction class is designed for creating
9
+# complex and flexible annotation graphics. As the main part, it uses a use-defined function
10
+# to define the graphics. It also keeps information of the size of the plotting regions of the annotation.
11
+# And most importantly, it allows subsetting of the annotation to draw a subset of the graphics, which
12
+# is the base for the splitting of the annotations.
13
+#
14
+# See `AnnotationFunction` constructor for details.
8 15
 #
9 16
 AnnotationFunction = setClass("AnnotationFunction",
10 17
 	slots = list(
... ...
@@ -69,16 +76,17 @@ anno_width_and_height = function(which, width = NULL, height = NULL,
69 76
 
70 77
 
71 78
 # == title
72
-# Constructor of AnnotationFunction class
79
+# Constructor of AnnotationFunction Class
73 80
 #
74 81
 # == param
75
-# -fun A function which defines how to draw annotation. See **Details** section.
76
-# -fun_name The name of the function. It is only used for `show,AnnotationFunction-method`.
82
+# -fun A function which defines how to draw this annotation. See **Details** section.
83
+# -fun_name The name of the function. It is only used for printing the object.
77 84
 # -which Whether it is drawn as a column annotation or a row annotation?
78
-# -var_imported The name of the object or the objects themselves that the annotation function depends on. See **Details** section.
79
-# -n Number of observations in the annotation. It is not mandatory, but it is better to provide this information.
85
+# -var_import The names of the variables or the variable themselves that the annotation function depends on. See **Details** section.
86
+# -n Number of observations in the annotation. It is not mandatory, but it is better to provide this information
87
+#   so that the higher order `HeatmapAnnotation` knows it and it can perform check on the consistency of annotations and heatmaps.
80 88
 # -data_scale The data scale on the data axis (y-axis for column annotation and x-axis for row annotation). It is only used
81
-#             when `decoration_annotation` is used with "native" unit coordinates.
89
+#             when `decorate_annotation` is used with "native" unit coordinates.
82 90
 # -subset_rule The rule of subsetting variables in ``var_import``. It should be set when users want the final object to
83 91
 #              be subsetable. See **Details** section.
84 92
 # -subsetable Whether the object is subsetable?
... ...
@@ -88,12 +96,83 @@ anno_width_and_height = function(which, width = NULL, height = NULL,
88 96
 #        the width must be an absolute unit.
89 97
 #
90 98
 # == details
91
-# The AnnotationFunction class is a wrapper of the function which draws heatmap annotation.
99
+# A normal R function defines how to draw the annotation graphics. As expected, the main part of the AnnotationFunction
100
+# class is this function. The function defines how to draw at specific positions which correspond to rows or columns
101
+# in the heatmap. The function should have three arguments: ``index``, ``k`` and ``n`` (the names of the arguments can
102
+# be arbitory) where ``k`` and ``n`` are optional. ``index`` corresponds to the indices of rows or columns of the heatmap.
103
+# The value of ``index`` is not necessarily to be the whole row indices or column indices. It can also be a subset of
104
+# the indices if the annotation is split into slices according to the split of the heatmap. The value in ``index`` is
105
+# always sorted according to the reordering of heatmap rows or columns (e.g. by clustering). So, ``index`` actually contains
106
+# a list of row or column indices for the current slice after row or column reordering. This type of design makes sure
107
+# the annotation graphics are drawn at the correct positions and can be correctly corresponded to the heatmap rows or columns.
108
+# 
109
+# As mentioned, annotation can be split into slices. ``k`` corresponds to the current slice and ``n`` corresponds to
110
+# the total number of slices. The information of ``k`` and ``n`` sometimes can be useful, for example, we want to add axis
111
+# in the annotation, and if it is a column annotation and axis is drawn on the very right of the annotation area, the axis
112
+# is only drawn when ``k == n``.
113
+#
114
+# Since the function only allows ``index``, ``k`` and ``n``, the function sometimes uses several external variables which can
115
+# not be defined inside the function, e.g. the data points for the annotation. These variables should be imported
116
+# into the AnnotationFunction class so that the function can correctly find these variables. 
117
+#
118
+# One important feature for AnnotationFunction class is it can be subsetable. To allow subsetting of the object,
119
+# users need to define the rule for the imported variables if there is any. The rules are simple function which
120
+# accpets the variable and indices, and returns the subset of the variable. The subset rule functions implemented
121
+# in this package are `subset_gp`, `subset_matrix_by_row` and `subset_vector`. These three functions are enough for
122
+# most of the cases.
123
+#
124
+# In following, we defined three AnnotationFunction objects: 
125
+#
126
+# 1. It needs external variable and support subsetting
127
+#
128
+#	x = 1:10
129
+#	anno1 = AnnotationFunction(
130
+#		fun = function(index) {
131
+#			n = length(index)
132
+#			pushViewport(viewport())
133
+#			grid.points(1:n, x[index])
134
+#			popViewport()
135
+#		},
136
+#		var_imported = list(x = x),
137
+#		n = 10,
138
+#		subset_rule = list(x = subset_vector),
139
+#		subsetable = TRUE
140
+#	)
141
+#
142
+# 2. The data variable is defined inside the function and no need to import other variables.
143
+#
144
+#	anno2 = AnnotationFunction(
145
+#		fun = function(index) {
146
+#			x = 1:10
147
+#			n = length(index)
148
+#			pushViewport(viewport())
149
+#			grid.points(1:n, x[index])
150
+#			popViewport()
151
+#		},
152
+#		n = 10,
153
+#		subsetable = TRUE
154
+#	)
155
+#
156
+# 3. The most compact way to only specify the function to the constructor.
157
+#
158
+#	anno3 = AnnotationFunction(
159
+#		fun = function(index) {
160
+#			x = 1:10
161
+#			n = length(index)
162
+#			pushViewport(viewport())
163
+#			grid.points(1:n, x[index])
164
+#			popViewport()
165
+#		}
166
+#	)
92 167
 #
93
-# If the annotation function is subsetable, the annotation graphics can be split by rows or by columns
94
-# according to the split of the heatmap.
168
+# Finally, you need to push a viewport for graphics and finally pop the viewport.
169
+#
170
+# In the package, quite a lot annotation function are constructed by `AnnotationFunction` constructor:
171
+# `anno_empty`, `anno_image`, `anno_points`, `anno_lines`, `anno_barplot`, `anno_boxplot`, `anno_histogram`,
172
+# `anno_density`, `anno_joyplot`, `anno_horizon`, `anno_text` and `anno_mark`. Thess built-in annotation functions
173
+# are all subsettable.
95 174
 AnnotationFunction = function(fun, fun_name = "", which = c("column", "row"), 
96
-	var_imported = list(), n = 0, data_scale = c(0, 1), subset_rule = list(), 
175
+	var_import = list(), n = 0, data_scale = c(0, 1), subset_rule = list(), 
97 176
 	subsetable = FALSE, width = NULL, height = NULL) {
98 177
 
99 178
 	which = match.arg(which)[1]
... ...
@@ -114,25 +193,32 @@ AnnotationFunction = function(fun, fun_name = "", which = c("column", "row"),
114 193
 	anno@n = n
115 194
 	anno@data_scale = data_scale
116 195
 
117
-	anno@var_env = new.env()
118
-	if(is.character(var_imported)) {
119
-		for(nm in var_imported) {
120
-			anno@var_env[[nm]] = get(nm, envir = parent.frame())
121
-		}
122
-	} else if(inherits(var_imported, "list")) {
123
-		if(is.null(names(var_imported))) {
124
-			var_imported_nm = sapply(as.list(substitute(var_imported))[-1], as.character)
125
-			names(var_imported) = var_imported_nm
126
-		}
196
+	if(length(var_import)) {
197
+		anno@var_env = new.env()
198
+		if(is.character(var_import)) {
199
+			for(nm in var_import) {
200
+				anno@var_env[[nm]] = get(nm, envir = parent.frame())
201
+			}
202
+		} else if(inherits(var_import, "list")) {
203
+			if(is.null(names(var_import))) {
204
+				var_imported_nm = sapply(as.list(substitute(var_import))[-1], as.character)
205
+				names(var_import) = var_imported_nm
206
+			}
127 207
 
128
-		for(nm in names(var_imported)) {
129
-			anno@var_env[[nm]] = var_imported[[nm]]
208
+			for(nm in names(var_import)) {
209
+				anno@var_env[[nm]] = var_import[[nm]]
210
+			}
211
+		} else {
212
+			stop_wrap("`var_import` needs to be a character vector which contains variable names or a list of variables")
130 213
 		}
214
+		environment(fun) = anno@var_env
131 215
 	} else {
132
-		stop_wrap("`var_import` needs to be a character vector which contains variable names or a list of variables")
216
+		anno@var_env = environment(fun)
217
+	}
218
+
219
+	if(length(as.list(formals(fun))) == 1) {
220
+		formals(fun) = alist(index = , k = 1, n = 1)
133 221
 	}
134
-	
135
-	environment(fun) = anno@var_env
136 222
 	anno@fun = fun
137 223
 	
138 224
 	if(is.null(subset_rule)) {
... ...
@@ -173,7 +259,8 @@ AnnotationFunction = function(fun, fun_name = "", which = c("column", "row"),
173 259
 # -i A vector of indices.
174 260
 #
175 261
 # == details
176
-# One good thing for designing the `AnnotationFunction-class` can be subsetted.
262
+# One good thing for designing the `AnnotationFunction-class` object is it can be subsetted,
263
+# and this is the base for the splitting of the annotations.
177 264
 #
178 265
 # == example
179 266
 # anno = anno_simple(1:10)
... ...
@@ -204,11 +291,13 @@ AnnotationFunction = function(fun, fun_name = "", which = c("column", "row"),
204 291
 }
205 292
 
206 293
 # == title
207
-# Draw the AnnotationFunction object
294
+# Draw the AnnotationFunction Object
208 295
 #
209 296
 # == param
210 297
 # -object The `AnnotationFunction-class` object.
211 298
 # -index Index of observations.
299
+# -k Current index of slice.
300
+# -n Total number of slices.
212 301
 # -test Is it in test mode? The value can be logical or a text which is plotted as the title of plot.
213 302
 #
214 303
 # == detail
... ...
@@ -219,7 +308,7 @@ AnnotationFunction = function(fun, fun_name = "", which = c("column", "row"),
219 308
 # 
220 309
 setMethod(f = "draw",
221 310
 	signature = "AnnotationFunction",
222
-	definition = function(object, index, test = FALSE) {
311
+	definition = function(object, index, k = 1, n = 1, test = FALSE) {
223 312
 		
224 313
 	if(is.character(test)) {
225 314
 		test2 = TRUE
... ...
@@ -242,7 +331,7 @@ setMethod(f = "draw",
242 331
     # names should be passed to the data viewport
243 332
 	pushViewport(viewport(width = anno_width, height = anno_height))
244 333
 	vp_name1 = current.viewport()$name
245
-	object@fun(index)
334
+	object@fun(index, k, n)
246 335
 	if(test2) {
247 336
 		grid.text(test, y = unit(1, "npc") + unit(2, "mm"), just = "bottom")
248 337
 
... ...
@@ -283,6 +372,8 @@ setMethod(f = "draw",
283 372
 # In `AnnotationFunction-class`, there is an environment which stores some external variables
284 373
 # for the annotation function. This `copy_all,AnnotationFunction-method` hard copy all the variables
285 374
 # in that environment to a new environment.
375
+#
376
+# The environment is at ``object@var_env``.
286 377
 setMethod(f = "copy_all",
287 378
 	signature = "AnnotationFunction",
288 379
 	definition = function(object) {
... ...
@@ -333,112 +424,22 @@ setMethod(f = "show",
333 424
 	
334 425
 })
335 426
 
336
-# == title
337
-# Width of the AnnotationFunction object
338
-#
339
-# == param
340
-# -object The `AnnotationFunction-class` object.
341
-#
342
-setMethod(f = "width",
343
-	signature = "AnnotationFunction",
344
-	definition = function(object) {
345
-	object@width
346
-})
347
-
348
-# == title
349
-# Assign the Width of the AnnotationFunction object
350
-#
351
-# == param
352
-# -object The `AnnotationFunction-class` object.
353
-# -value A `grid::unit` object.
354
-# -... Other arguments
355
-#
356
-setReplaceMethod(f = "width",
357
-	signature = "AnnotationFunction",
358
-	definition = function(object, value, ...) {
359
-	object@width = value
360
-	object
361
-})
362
-
363
-# == title
364
-# Height of the AnnotationFunction object
365
-#
366
-# == param
367
-# -object The `AnnotationFunction-class` object.
368
-#
369
-setMethod(f = "height",
370
-	signature = "AnnotationFunction",
371
-	definition = function(object) {
372
-	object@height
373
-})
374
-
375
-# == title
376
-# Assign the Height of the AnnotationFunction object
377
-#
378
-# == param
379
-# -object The `AnnotationFunction-class` object.
380
-# -value A `grid::unit` object.
381
-# -... Other arguments
382
-#
383
-setReplaceMethod(f = "height",
384
-	signature = "AnnotationFunction",
385
-	definition = function(object, value, ...) {
386
-	object@height = value
387
-	object
388
-})
389
-
390
-# == title
391
-# Size of the AnnotationFunction object
392
-#
393
-# == param
394
-# -object The `AnnotationFunction-class` object.
395
-#
396
-# == detail
397
-# It returns the width if it is a row annotation and the height if it is a column annotation.
398
-#
399
-setMethod(f = "size",
400
-	signature = "AnnotationFunction",
401
-	definition = function(object) {
402
-	if(object@which == "row") {
403
-		object@width
404
-	} else {
405
-		object@height
406
-	}
407
-})
408
-
409
-# == title
410
-# Assign the Size of the AnnotationFunction object
411
-#
412
-# == param
413
-# -object The `AnnotationFunction-class` object.
414
-# -value A `grid::unit` object.
415
-# -... Other arguments
416
-#
417
-# == detail
418
-# It assigns the width if it is a row annotation and the height if it is a column annotation.
419
-#
420
-setReplaceMethod(f = "size",
421
-	signature = "AnnotationFunction",
422
-	definition = function(object, value, ...) {
423
-	if(object@which == "row") {
424
-		object@width = value
425
-	} else {
426
-		object@height = value
427
-	}
428
-	object
429
-})
430
-
431 427
 # == title
432 428
 # Number of Observations
433 429
 #
434 430
 # == param
435
-# -x The `AnnotationFunction-class` object.
431
+# -object The `AnnotationFunction-class` object.
432
+# -... other arguments
436 433
 #
437 434
 # == details
438
-# It returns the ``n`` slot in the object.
439
-nobs.AnnotationFunction = function(x) {
440
-	if(x@n > 0) {
441
-		x@n
435
+# It returns the ``n`` slot in the object. If there does not exist, it returns ``NA``.
436
+#
437
+# == example
438
+# anno = anno_points(1:10)
439
+# nobs(anno)
440
+nobs.AnnotationFunction = function(object, ...) {
441
+	if(object@n > 0) {
442
+		object@n
442 443
 	} else {
443 444
 		NA
444 445
 	}
... ...
@@ -66,7 +66,22 @@ anno_empty = function(which = c("column", "row"), border = TRUE, width = NULL, h
66 66
 	return(anno) 
67 67
 }
68 68
 
69
+# == title
70
+# Subset the Matrix by Rows
71
+#
72
+# == param
73
+# -x A matrix
74
+# -i The row indices.
75
+#
69 76
 subset_matrix_by_row = function(x, i) x[i, , drop = FALSE]
77
+
78
+# == title
79
+# Subset the vector
80
+#
81
+# == param
82
+# -x A vector
83
+# -i The indices
84
+#
70 85
 subset_vector = function(x, i) x[i]
71 86
 
72 87
 # == title
... ...
@@ -81,7 +96,7 @@ subset_vector = function(x, i) x[i]
81 96
 #      vector of colors. Normally it is generated by `circlize::colorRamp2`. If ``x`` is discrete
82 97
 #      (numeric or character) and needs a discrete color mapping, ``col`` should be a vector of 
83 98
 #      colors with levels in ``x`` as vector names. If ``col`` is not specified, the color mapping
84
-#      is randomly generated by `default_col`.
99
+#      is randomly generated by ``ComplexHeatmap:::default_col``.
85 100
 # -na_col Color for NA value.
86 101
 # -which Whether it is a column annotation or a row annotation?
87 102
 # -border Wether draw borders of the annotation region?
... ...
@@ -115,7 +130,7 @@ subset_vector = function(x, i) x[i]
115 130
 # anno = anno_simple(1:10, pch = c(1:4, NA, 6:8, NA, 10))
116 131
 # draw(anno, test = "pch has NA values")
117 132
 #
118
-# anno = anno_simple(1:10, pch = c(rep("A", 5, rep(NA, 5))))
133
+# anno = anno_simple(1:10, pch = c(rep("A", 5), rep(NA, 5)))
119 134
 # draw(anno, test = "pch has NA values")
120 135
 #
121 136
 # pch = matrix(1:20, nc = 2)
... ...
@@ -289,7 +304,7 @@ anno_simple = function(x, col, na_col = "grey",
289 304
 # == details
290 305
 # This function supports image formats in ``png``, ``svg``, ``pdf``, ``eps``, ``jpeg/jpg``, ``tiff``. 
291 306
 # ``png``, ``jpeg/jpg`` and ``tiff`` images are imported by `png::readPNG`, `jpeg::readJPEG` and 
292
-# `tiff::readTIFF`, and drawn by `grid.grid.raster`. ``svg`` images are firstly reformatted by `rsvg::rsvg_svg`
307
+# `tiff::readTIFF`, and drawn by `grid::grid.raster`. ``svg`` images are firstly reformatted by `rsvg::rsvg_svg`
293 308
 # and then imported by `grImport2::readPicture` and drawn by `grImport2::grid.picture`. ``pdf`` and ``eps``
294 309
 # images are imported by `grImport::PostScriptTrace` and `grImport::readPicture`, later drawn by `grImport::grid.picture`.
295 310
 #
... ...
@@ -401,7 +416,7 @@ anno_image = function(image, which = c("column", "row"), border = TRUE,
401 416
 		n = length(index)
402 417
 
403 418
 		pushViewport(viewport())
404
-		asp = convertHeight(unit(1, "npc") - space*2, "mm", valueOnly = TRUE)/convertWidth(unit(1/n, "npc") - space*2, "mm", value = TRUE)
419
+		asp = convertHeight(unit(1, "npc") - space*2, "mm", valueOnly = TRUE)/convertWidth(unit(1/n, "npc") - space*2, "mm", valueOnly = TRUE)
405 420
 		grid.rect(x = (1:n - 0.5)/n, width = 1/n, gp = subset_gp(gp, index))
406 421
 		for(i in seq_len(n)) {
407 422
 			if(identical(image_list[[i]], NA)) next
... ...
@@ -430,7 +445,7 @@ anno_image = function(image, which = c("column", "row"), border = TRUE,
430 445
 		n = length(index)
431 446
 
432 447
 		pushViewport(viewport())
433
-		asp = convertHeight(unit(1/n, "npc") - space*2, "mm", valueOnly = TRUE)/convertWidth(unit(1, "npc") - space*2, "mm", value = TRUE)
448
+		asp = convertHeight(unit(1/n, "npc") - space*2, "mm", valueOnly = TRUE)/convertWidth(unit(1, "npc") - space*2, "mm", valueOnly = TRUE)
434 449
 		grid.rect(y = (n - 1:n + 0.5)/n, height = 1/n, gp = subset_gp(gp, index))
435 450
 		for(i in seq_len(n)) {
436 451
 			if(identical(image_list[[i]], NA)) next
... ...
@@ -621,7 +636,7 @@ anno_points = function(x, which = c("column", "row"), border = TRUE, gp = gpar()
621 636
 	axis_param = validate_axis_param(axis_param, which)
622 637
 	axis_grob = if(axis) construct_axis_grob(axis_param, which, data_scale) else NULL
623 638
 
624
-	row_fun = function(index) {
639
+	row_fun = function(index, k = 1, N = 1) {
625 640
 		n = length(index)
626 641
 
627 642
 		pushViewport(viewport(xscale = data_scale, yscale = c(0.5, n+0.5)))
... ...
@@ -634,12 +649,17 @@ anno_points = function(x, which = c("column", "row"), border = TRUE, gp = gpar()
634 649
 			grid.points(value[index], n - seq_along(index) + 1, gp = gp, default.units = "native", 
635 650
 				pch = pch[index], size = size[index])
636 651
 		}
652
+		if(axis_param$side == "top") {
653
+			if(k > 1) axis = FALSE
654
+		} else if(axis_param$side == "bottom") {
655
+			if(k < N) axis = FALSE
656
+		}
637 657
 		if(axis) grid.draw(axis_grob)
638 658
 		if(border) grid.rect(gp = gpar(fill = "transparent"))
639 659
 		popViewport()
640 660
 	}
641 661
 
642
-	column_fun = function(index) {
662
+	column_fun = function(index, k = 1, N = 1) {
643 663
 		n = length(index)
644 664
 		
645 665
 		pushViewport(viewport(yscale = data_scale, xscale = c(0.5, n+0.5)))
... ...
@@ -650,6 +670,11 @@ anno_points = function(x, which = c("column", "row"), border = TRUE, gp = gpar()
650 670
 		} else {
651 671
 			grid.points(seq_along(index), value[index], gp = gp, default.units = "native", pch = pch[index], size = size[index])
652 672
 		}
673
+		if(axis_param$side == "left") {
674
+			if(k > 1) axis = FALSE
675
+		} else if(axis_param$side == "right") {
676
+			if(k < N) axis = FALSE
677
+		}
653 678
 		if(axis) grid.draw(axis_grob)
654 679
 		if(border) grid.rect(gp = gpar(fill = "transparent"))
655 680
 		popViewport()
... ...
@@ -717,7 +742,7 @@ update_anno_extend = function(anno, axis_grob, axis_param) {
717 742
 # -add_points Whether to add points on the lines?
718 743
 # -pch Point type. The length setting is the same as ``gp``.
719 744
 # -size Point size, the value should be a `grid::unit` object. The length setting is the same as ``gp``.
720
-# -pt_size Graphic parameters for points. The length setting is the same as ``gp``.
745
+# -pt_gp Graphic parameters for points. The length setting is the same as ``gp``.
721 746
 # -ylim Data ranges. By default it is ``range(x)``.
722 747
 # -extend The extension to both side of ``ylim``. The value is a percent value corresponding to ``ylim[2] - ylim[1]``.
723 748
 # -axis Whether to add axis?
... ...
@@ -791,7 +816,7 @@ anno_lines = function(x, which = c("column", "row"), border = TRUE, gp = gpar(),
791 816
 	axis_param = validate_axis_param(axis_param, which)
792 817
 	axis_grob = if(axis) construct_axis_grob(axis_param, which, data_scale) else NULL
793 818
 
794
-	row_fun = function(index) {
819
+	row_fun = function(index, k = 1, N = 1) {
795 820
 		n = length(index)
796 821
 
797 822
 		pushViewport(viewport(xscale = data_scale, yscale = c(0.5, n+0.5)))
... ...
@@ -812,12 +837,17 @@ anno_lines = function(x, which = c("column", "row"), border = TRUE, gp = gpar(),
812 837
 					pch = pch[index], size = size[index])
813 838
 			}
814 839
 		}
840
+		if(axis_param$side == "top") {
841
+			if(k > 1) axis = FALSE
842
+		} else if(axis_param$side == "bottom") {
843
+			if(k < N) axis = FALSE
844
+		}
815 845
 		if(axis) grid.draw(axis_grob)
816 846
 		if(border) grid.rect(gp = gpar(fill = "transparent"))
817 847
 		popViewport()
818 848
 	}
819 849
 
820
-	column_fun = function(index) {
850
+	column_fun = function(index, k = 1, N = 1) {
821 851
 		n = length(index)
822 852
 
823 853
 		pushViewport(viewport(yscale = data_scale, xscale = c(0.5, n+0.5)))
... ...
@@ -837,6 +867,11 @@ anno_lines = function(x, which = c("column", "row"), border = TRUE, gp = gpar(),
837 867
 					pch = pch[index], size = size[index])
838 868
 			}
839 869
 		}
870
+		if(axis_param$side == "left") {
871
+			if(k > 1) axis = FALSE
872
+		} else if(axis_param$side == "right") {
873
+			if(k < N) axis = FALSE
874
+		}
840 875
 		if(axis) grid.draw(axis_grob)
841 876
 		if(border) grid.rect(gp = gpar(fill = "transparent"))
842 877
 		popViewport()
... ...
@@ -967,7 +1002,7 @@ anno_barplot = function(x, baseline = 0, which = c("column", "row"), border = TR
967 1002
 	axis_param = validate_axis_param(axis_param, which)
968 1003
 	axis_grob = if(axis) construct_axis_grob(axis_param, which, data_scale) else NULL
969 1004
 
970
-	row_fun = function(index) {
1005
+	row_fun = function(index, k = 1, N = 1) {
971 1006
 		n = length(index)
972 1007
 		
973 1008
 		pushViewport(viewport(xscale = data_scale, yscale = c(0.5, n+0.5)))
... ...
@@ -982,11 +1017,16 @@ anno_barplot = function(x, baseline = 0, which = c("column", "row"), border = TR
982 1017
 				grid.rect(x = x_coor, y = n - seq_along(index) + 1, width = abs(width), height = 1*bar_width, default.units = "native", gp = subset_gp(gp, i))
983 1018
 			}
984 1019
 		}
1020
+		if(axis_param$side == "top") {
1021
+			if(k > 1) axis = FALSE
1022
+		} else if(axis_param$side == "bottom") {
1023
+			if(k < N) axis = FALSE
1024
+		}
985 1025
 		if(axis) grid.draw(axis_grob)
986 1026
 		if(border) grid.rect(gp = gpar(fill = "transparent"))
987 1027
 		popViewport()
988 1028
 	}
989
-	column_fun = function(index) {
1029
+	column_fun = function(index, k = 1, N = 1) {
990 1030
 		n = length(index)
991 1031
 	
992 1032
 		pushViewport(viewport(yscale = data_scale, xscale = c(0.5, n+0.5)))
... ...
@@ -1001,6 +1041,11 @@ anno_barplot = function(x, baseline = 0, which = c("column", "row"), border = TR
1001 1041
 				grid.rect(y = y_coor, x = seq_along(index), height = abs(height), width = 1*bar_width, default.units = "native", gp = subset_gp(gp, i))
1002 1042
 			}
1003 1043
 		}
1044
+		if(axis_param$side == "left") {
1045
+			if(k > 1) axis = FALSE
1046
+		} else if(axis_param$side == "right") {
1047
+			if(k < N) axis = FALSE
1048
+		}
1004 1049
 		if(axis) grid.draw(axis_grob)
1005 1050
 		if(border) grid.rect(gp = gpar(fill = "transparent"))
1006 1051
 		popViewport()
... ...
@@ -1110,7 +1155,7 @@ anno_boxplot = function(x, which = c("column", "row"), border = TRUE,
1110 1155
 	axis_param = validate_axis_param(axis_param, which)
1111 1156
 	axis_grob = if(axis) construct_axis_grob(axis_param, which, data_scale) else NULL
1112 1157
 
1113
-	row_fun = function(index) {
1158
+	row_fun = function(index, k = 1, N = 1) {
1114 1159
 
1115 1160
 		n_all = length(value)
1116 1161
 		value = value[index]
... ...
@@ -1149,11 +1194,16 @@ anno_boxplot = function(x, which = c("column", "row"), border = TRUE,
1149 1194
 					default.units = "native", gp = subset_gp(gp, i), pch = pch[i], size = size[i])
1150 1195
 			}
1151 1196
 		}
1197
+		if(axis_param$side == "top") {
1198
+			if(k > 1) axis = FALSE
1199
+		} else if(axis_param$side == "bottom") {
1200
+			if(k < N) axis = FALSE
1201
+		}
1152 1202
 		if(axis) grid.draw(axis_grob)
1153 1203
 		if(border) grid.rect(gp = gpar(fill = "transparent"))
1154 1204
 		popViewport()
1155 1205
 	}
1156
-	column_fun = function(index) {
1206
+	column_fun = function(index, k = 1, N = 1) {
1157 1207
 		value = value[index]
1158 1208
 		boxplot_stats = boxplot(value, plot = FALSE)$stats
1159 1209
 
... ...
@@ -1189,6 +1239,11 @@ anno_boxplot = function(x, which = c("column", "row"), border = TRUE,
1189 1239
 					default.units = "native", gp = subset_gp(gp, i), pch = pch[i], size = size[i])
1190 1240
 			}
1191 1241
 		}
1242
+		if(axis_param$side == "left") {
1243
+			if(k > 1) axis = FALSE
1244
+		} else if(axis_param$side == "right") {
1245
+			if(k < N) axis = FALSE
1246
+		}
1192 1247
 		if(axis) grid.draw(axis_grob)
1193 1248
 		if(border) grid.rect(gp = gpar(fill = "transparent"))
1194 1249
 		popViewport()
... ...
@@ -1288,7 +1343,7 @@ anno_histogram = function(x, which = c("column", "row"), n_breaks = 11,
1288 1343
 	axis_param = validate_axis_param(axis_param, which)
1289 1344
 	axis_grob = if(axis) construct_axis_grob(axis_param, which, xscale) else NULL
1290 1345
 
1291
-	row_fun = function(index) {
1346
+	row_fun = function(index, k = 1, N = 1) {
1292 1347
 		
1293 1348
 		n_all = length(value)
1294 1349
 		value = value[index]
... ...
@@ -1305,11 +1360,16 @@ anno_histogram = function(x, which = c("column", "row"), n_breaks = 11,
1305 1360
 			popViewport()
1306 1361
 		}
1307 1362
 		pushViewport(viewport(xscale = xscale))
1363
+		if(axis_param$side == "top") {
1364
+			if(k > 1) axis = FALSE
1365
+		} else if(axis_param$side == "bottom") {
1366
+			if(k < N) axis = FALSE
1367
+		}
1308 1368
 		if(axis) grid.draw(axis_grob)
1309 1369
 		if(border) grid.rect(gp = gpar(fill = "transparent"))
1310 1370
 		popViewport()
1311 1371
 	}
1312
-	column_fun = function(index) {
1372
+	column_fun = function(index, k = 1, N = 1) {
1313 1373
 		
1314 1374
 		n_all = length(value)
1315 1375
 		value = value[index]
... ...
@@ -1332,6 +1392,11 @@ anno_histogram = function(x, which = c("column", "row"), n_breaks = 11,
1332 1392
 			popViewport()
1333 1393
 		}
1334 1394
 		pushViewport(viewport(yscale = yscale))
1395
+		if(axis_param$side == "left") {
1396
+			if(k > 1) axis = FALSE
1397
+		} else if(axis_param$side == "right") {
1398
+			if(k < N) axis = FALSE
1399
+		}
1335 1400
 		if(axis) grid.draw(axis_grob)
1336 1401
 		if(border) grid.rect(gp = gpar(fill = "transparent"))
1337 1402
 		popViewport()
... ...
@@ -1390,13 +1455,14 @@ anno_histogram = function(x, which = c("column", "row"), n_breaks = 11,
1390 1455
 # An annotation function which can be used in `HeatmapAnnotation`.
1391 1456
 #
1392 1457
 # == example
1393
-# anno = anno_density(t(m), which = "row")
1458
+# m = matrix(rnorm(100), 10)
1459
+# anno = anno_density(m, which = "row")
1394 1460
 # draw(anno, test = "normal density")
1395
-# anno = anno_density(t(m), which = "row", type = "violin")
1461
+# anno = anno_density(m, which = "row", type = "violin")
1396 1462
 # draw(anno, test = "violin")
1397
-# anno = anno_density(t(m), which = "row", type = "heatmap")
1463
+# anno = anno_density(m, which = "row", type = "heatmap")
1398 1464
 # draw(anno, test = "heatmap")
1399
-# anno = anno_density(t(m), which = "row", type = "heatmap", 
1465
+# anno = anno_density(m, which = "row", type = "heatmap", 
1400 1466
 #     heatmap_colors = c("white", "orange"))
1401 1467
 # draw(anno, test = "heatmap, colors")
1402 1468
 anno_density = function(x, which = c("column", "row"),
... ...
@@ -1457,7 +1523,7 @@ anno_density = function(x, which = c("column", "row"),
1457 1523
 	axis_param = validate_axis_param(axis_param, which)
1458 1524
 	axis_grob = if(axis) construct_axis_grob(axis_param, which, xscale) else NULL
1459 1525
 
1460
-	row_fun = function(index) {
1526
+	row_fun = function(index, k = 1, N = 1) {
1461 1527
 		
1462 1528
 		n = length(index)
1463 1529
 		value = value[index]
... ...
@@ -1502,11 +1568,16 @@ anno_density = function(x, which = c("column", "row"),
1502 1568
 			popViewport()
1503 1569
 		}
1504 1570
 		pushViewport(viewport(xscale = xscale))
1571
+		if(axis_param$side == "top") {
1572
+			if(k > 1) axis = FALSE
1573
+		} else if(axis_param$side == "bottom") {
1574
+			if(k < N) axis = FALSE
1575
+		}
1505 1576
 		if(axis) grid.draw(axis_grob)
1506 1577
 		if(border) grid.rect(gp = gpar(fill = "transparent"))
1507 1578
 		popViewport()
1508 1579
 	}
1509
-	column_fun = function(index) {
1580
+	column_fun = function(index, k = 1, N = 1) {
1510 1581
 
1511 1582
 		n_all = length(value)
1512 1583
 		value = value[index]
... ...
@@ -1573,6 +1644,11 @@ anno_density = function(x, which = c("column", "row"),
1573 1644
 			popViewport()
1574 1645
 		}
1575 1646
 		pushViewport(viewport(yscale = yscale))
1647
+		if(axis_param$side == "left") {
1648
+			if(k > 1) axis = FALSE
1649
+		} else if(axis_param$side == "right") {
1650
+			if(k < N) axis = FALSE
1651
+		}
1576 1652
 		if(axis) grid.draw(axis_grob)
1577 1653
 		if(border) grid.rect(gp = gpar(fill = "transparent"))
1578 1654
 		popViewport()
... ...
@@ -1593,7 +1669,7 @@ anno_density = function(x, which = c("column", "row"),
1593 1669
 		n = n,
1594 1670
 		data_scale = xscale,
1595 1671
 		var_import = list(value, gp, border, type, axis, axis_param, axis_grob, xscale, yscale, density_x,
1596
-			density_y, min_density_x, max_density_x, joyplot_scale)
1672
+			density_y, min_density_x, max_density_x, joyplot_scale, heatmap_colors)
1597 1673
 	)
1598 1674
 
1599 1675
 	if(type == "heatmap") {
... ...
@@ -1652,11 +1728,11 @@ anno_text = function(x, which = c("column", "row"), gp = gpar(),
1652 1728
 	rot = guess_rot(), just = guess_just(), 
1653 1729
 	offset = guess_location(), location = guess_location(),
1654 1730
 	width = NULL, height = NULL) {
1655
-
1656
-	if(exists(".__under_SingleAnnotation__", envir = parent.frame())) {
1657
-		which = get("which", envir = parent.frame())
1658
-	} else {
1731
+	
1732
+	if(is.null(.ENV$current_annotation_which)) {
1659 1733
 		which = match.arg(which)[1]
1734
+	} else {
1735
+		which = .ENV$current_annotation_which
1660 1736
 	}
1661 1737
 
1662 1738
 	n = length(x)
... ...
@@ -1807,7 +1883,7 @@ anno_joyplot = function(x, which = c("column", "row"), gp = gpar(fill = "#000000
1807 1883
 	if(is.matrix(x) || is.data.frame(x)) {
1808 1884
 		value = vector("list", ncol(x))
1809 1885
 		for(i in seq_len(ncol(x))) {
1810
-			value[[i]] = cbind(seq_len(nrow(x), x[, i]))
1886
+			value[[i]] = cbind(seq_len(nrow(x)), x[, i])
1811 1887
 		}
1812 1888
 	} else if(inherits(x, "list")){
1813 1889
 		if(all(sapply(x, is.atomic))) {
... ...
@@ -1842,7 +1918,7 @@ anno_joyplot = function(x, which = c("column", "row"), gp = gpar(fill = "#000000
1842 1918
 	axis_param = validate_axis_param(axis_param, which)
1843 1919
 	axis_grob = if(axis) construct_axis_grob(axis_param, which, xscale) else NULL
1844 1920
 
1845
-	row_fun = function(index) {
1921
+	row_fun = function(index, k = 1, N = 1) {
1846 1922
 
1847 1923
 		n_all = length(value)
1848 1924
 		value = value[index]
... ...
@@ -1867,10 +1943,15 @@ anno_joyplot = function(x, which = c("column", "row"), gp = gpar(fill = "#000000
1867 1943
 			popViewport()
1868 1944
 		}
1869 1945
 		pushViewport(viewport(xscale = xscale))
1946
+		if(axis_param$side == "top") {
1947
+			if(k > 1) axis = FALSE
1948
+		} else if(axis_param$side == "bottom") {
1949
+			if(k < N) axis = FALSE
1950
+		}
1870 1951
 		if(axis) grid.draw(axis_grob)
1871 1952
 		popViewport()
1872 1953
 	}
1873
-	column_fun = function(index) {
1954
+	column_fun = function(index, k = 1, N = 1) {
1874 1955
 
1875 1956
 		n_all = length(value)
1876 1957
 		value = value[index]
... ...
@@ -1900,6 +1981,11 @@ anno_joyplot = function(x, which = c("column", "row"), gp = gpar(fill = "#000000
1900 1981
 			popViewport()
1901 1982
 		}
1902 1983
 		pushViewport(viewport(yscale = yscale))
1984
+		if(axis_param$side == "left") {
1985
+			if(k > 1) axis = FALSE
1986
+		} else if(axis_param$side == "right") {
1987
+			if(k < N) axis = FALSE
1988
+		}
1903 1989
 		if(axis) grid.draw(axis_grob)
1904 1990
 		popViewport()
1905 1991
 	}
... ...
@@ -1938,7 +2024,7 @@ anno_joyplot = function(x, which = c("column", "row"), gp = gpar(fill = "#000000
1938 2024
 # -x A matrix or a list. If ``x`` is a matrix or a data frame, columns correspond to observations.
1939 2025
 # -which Whether it is a column annotation or a row annotation?
1940 2026
 # -gp Graphic parameters for the boxes. The length of the graphic parameters should be one or the number of observations.
1941
-#     There are two unstandard parameters specificly for horizon chart: ``pos_fill`` and ``neg_fill` controls the filled
2027
+#     There are two unstandard parameters specificly for horizon chart: ``pos_fill`` and ``neg_fill`` controls the filled
1942 2028
 #     color for positive values and negative values.
1943 2029
 # -n_slice Number of slices on y-axis.
1944 2030
 # -slice_size Height of the slice. If the value is not ``NULL``, ``n_slice`` will be recalculated. 
... ...
@@ -1956,7 +2042,7 @@ anno_joyplot = function(x, which = c("column", "row"), gp = gpar(fill = "#000000
1956 2042
 # == value
1957 2043
 # An annotation function which can be used in `HeatmapAnnotation`.
1958 2044
 #
1959
-# == detail
2045
+# == example
1960 2046
 # lt = lapply(1:20, function(x) cumprod(1 + runif(1000, -x/100, x/100)) - 1)
1961 2047
 # anno = anno_horizon(lt, which = "row")
1962 2048
 # draw(anno, test = "horizon chart")
... ...
@@ -1990,7 +2076,7 @@ anno_horizon = function(x, which = c("column", "row"),
1990 2076
 	if(is.matrix(x) || is.data.frame(x)) {
1991 2077
 		value = vector("list", ncol(x))
1992 2078
 		for(i in seq_len(ncol(x))) {
1993
-			value[[i]] = cbind(seq_len(nrow(x), x[, i]))
2079
+			value[[i]] = cbind(seq_len(nrow(x)), x[, i])
1994 2080
 		}
1995 2081
 	} else if(inherits(x, "list")){
1996 2082
 		if(all(sapply(x, is.atomic))) {
... ...
@@ -2041,7 +2127,7 @@ anno_horizon = function(x, which = c("column", "row"),
2041 2127
 	axis_param = validate_axis_param(axis_param, which)
2042 2128
 	axis_grob = if(axis) construct_axis_grob(axis_param, which, xscale) else NULL
2043 2129
 
2044
-	row_fun = function(index) {
2130
+	row_fun = function(index, k = 1, N = 1) {
2045 2131
 
2046 2132
 		n_all = length(value)
2047 2133
 		value = value[index]
... ...
@@ -2066,6 +2152,11 @@ anno_horizon = function(x, which = c("column", "row"),
2066 2152
 			popViewport()
2067 2153
 		}
2068 2154
 		pushViewport(viewport(xscale = xscale))
2155
+		if(axis_param$side == "top") {
2156
+			if(k > 1) axis = FALSE
2157
+		} else if(axis_param$side == "bottom") {
2158
+			if(k < N) axis = FALSE
2159
+		}
2069 2160
 		if(axis) grid.draw(axis_grob)
2070 2161
 		popViewport()
2071 2162
 	}
... ...
@@ -2215,6 +2306,9 @@ row_anno_points = function(...) {
2215 2306
 # See help page of `anno_barplot`
2216 2307
 #
2217 2308
 row_anno_barplot = function(...) {
2309
+	if(exists(".__under_SingleAnnotation__", envir = parent.frame())) {
2310
+		message("From this version of ComplexHeatmap, you can directly use `anno_barplot()` for row annotation if you call it in `rowAnnotation()`.")
2311
+	}
2218 2312
 	anno_barplot(..., which = "row")
2219 2313
 }
2220 2314
 
... ...
@@ -2234,6 +2328,9 @@ row_anno_barplot = function(...) {
2234 2328
 # See help page of `anno_boxplot`
2235 2329
 #
2236 2330
 row_anno_boxplot = function(...) {
2331
+	if(exists(".__under_SingleAnnotation__", envir = parent.frame())) {
2332
+		message("From this version of ComplexHeatmap, you can directly use `anno_boxplot()` for row annotation if you call it in `rowAnnotation()`.")
2333
+	}
2237 2334
 	anno_boxplot(..., which = "row")
2238 2335
 }
2239 2336
 
... ...
@@ -2252,6 +2349,9 @@ row_anno_boxplot = function(...) {
2252 2349
 # See help page of `anno_histogram`
2253 2350
 #
2254 2351
 row_anno_histogram = function(...) {
2352
+	if(exists(".__under_SingleAnnotation__", envir = parent.frame())) {
2353
+		message("From this version of ComplexHeatmap, you can directly use `anno_histogram()` for row annotation if you call it in `rowAnnotation()`.")
2354
+	}
2255 2355
 	anno_histogram(..., which = "row")
2256 2356
 }
2257 2357
 
... ...
@@ -2270,6 +2370,9 @@ row_anno_histogram = function(...) {
2270 2370
 # See help page of `anno_density`
2271 2371
 #
2272 2372
 row_anno_density = function(...) {
2373
+	if(exists(".__under_SingleAnnotation__", envir = parent.frame())) {
2374
+		message("From this version of ComplexHeatmap, you can directly use `anno_density()` for row annotation if you call it in `rowAnnotation()`.")
2375
+	}
2273 2376
 	anno_density(..., which = "row")
2274 2377
 }
2275 2378
 
... ...
@@ -2288,6 +2391,9 @@ row_anno_density = function(...) {
2288 2391
 # See help page of `anno_text`
2289 2392
 #
2290 2393
 row_anno_text = function(...) {
2394
+	if(exists(".__under_SingleAnnotation__", envir = parent.frame())) {
2395
+		message("From this version of ComplexHeatmap, you can directly use `anno_text()` for row annotation if you call it in `rowAnnotation()`.")
2396
+	}
2291 2397
 	anno_text(..., which = "row")
2292 2398
 }
2293 2399
 
... ...
@@ -2323,7 +2429,7 @@ row_anno_text = function(...) {
2323 2429
 #
2324 2430
 # m = matrix(1:1000, byrow = TRUE, nr = 100)
2325 2431
 # anno = anno_mark(at = c(1:4, 20, 60, 97:100), labels = month.name[1:10], which = "row")
2326
-# Heatmap(m, cluster_rows = F, cluster_columns = F) + rowAnnotation(mark = anno)
2432
+# Heatmap(m, cluster_rows = FALSE, cluster_columns = FALSE) + rowAnnotation(mark = anno)
2327 2433
 # Heatmap(m) + rowAnnotation(mark = anno)
2328 2434
 anno_mark = function(at, labels, which = c("column", "row"), 
2329 2435
 	side = ifelse(which == "column", "top", "right"),
... ...
@@ -2495,6 +2601,9 @@ anno_link = function(...) {
2495 2601
 # See help page of `anno_link`
2496 2602
 #
2497 2603
 row_anno_link = function(...) {
2604
+	if(exists(".__under_SingleAnnotation__", envir = parent.frame())) {
2605
+		message("From this version of ComplexHeatmap, you can directly use `anno_mark()` for row annotation if you call it in `rowAnnotation()`.")
2606
+	}
2498 2607
 	anno_link(..., which = "row")
2499 2608
 }
2500 2609
 
... ...
@@ -7,7 +7,7 @@
7 7
 # Class for Mapping Values to Colors
8 8
 #
9 9
 # == details
10
-# The `ColorMapping-class` handles color mapping with both discrete values and continuous values.
10
+# The `ColorMapping-class` handles color mapping for discrete values and continuous values.
11 11
 # Discrete values are mapped by setting a vector of colors and continuous values are mapped by setting
12 12
 # a color mapping function.
13 13
 #
... ...
@@ -16,7 +16,7 @@
16 16
 #
17 17
 # - `ColorMapping`: contructor methods.
18 18
 # - `map_to_colors,ColorMapping-method`: mapping values to colors.
19
-# - `color_mapping_legend,ColorMapping-method`: draw legend or get legend as a `grid::grob` object.
19
+# - `color_mapping_legend,ColorMapping-method`: draw legend or get legend as an object.
20 20
 #
21 21
 # == author
22 22
 # Zuguang Gu <z.gu@dkfz.de>
... ...
@@ -42,7 +42,7 @@ ColorMapping = setClass("ColorMapping",
42 42
 #         ``levels`` can be ignored.
43 43
 # -col_fun Color mapping function that maps continuous values to colors.
44 44
 # -breaks Breaks for the continuous color mapping. If ``col_fun`` is
45
-#         generated by `circlize::colorRamp2`, ``breaks`` can be ignored.
45
+#         generated by `circlize::colorRamp2`, ``breaks`` is automatically inferred from the color mapping function.
46 46
 # -na_col Colors for ``NA`` values.
47 47
 #
48 48
 # == detail
... ...
@@ -55,6 +55,12 @@ ColorMapping = setClass("ColorMapping",
55 55
 # == author
56 56
 # Zuguang Gu <z.gu@dkfz.de>
57 57
 #
58
+# == examples
59
+# cm = ColorMapping(colors = c("A" = "red", "B" = "black"))
60
+# cm
61
+# require(circlize)
62
+# col_fun = colorRamp2(c(0, 1), c("white", "red"))
63
+# cm = ColorMapping(col_fun = col_fun)
58 64
 ColorMapping = function(name, colors = NULL, levels = NULL,
59 65
 	col_fun = NULL, breaks = NULL, na_col = "#FFFFFF") {
60 66
 
... ...
@@ -168,12 +174,21 @@ setMethod(f = "show",
168 174
 # == details
169 175
 # It maps a vector of values to a vector of colors.
170 176
 #
177
+# This function provides a uniform way for discrete and continuous color mapping.
178
+#
171 179
 # == value
172 180
 # A vector of colors.
173 181
 #
174 182
 # == author
175 183
 # Zuguang Gu <z.gu@dkfz.de>
176 184
 #
185
+# == example
186
+# cm = ColorMapping(colors = c("A" = "red", "B" = "black"))
187
+# map_to_colors(cm, sample(c("A", "B"), 10, replace = TRUE))
188
+# require(circlize)
189
+# col_fun = colorRamp2(c(0, 1), c("white", "red"))
190
+# cm = ColorMapping(col_fun = col_fun)
191
+# map_to_colors(cm, runif(10))
177 192
 setMethod(f = "map_to_colors",
178 193
 	signature = "ColorMapping",
179 194
 	definition = function(object, x) {
... ...
@@ -211,56 +226,60 @@ setMethod(f = "map_to_colors",
211 226
 #
212 227
 # == param
213 228
 # -object A `ColorMapping-class` object.
214
-# -plot Whether to plot or just return legend object?
215
-# -title Title of the legend, by default it is the name of the legend
216
-# -title_gp Traphical parameters for legend title
217
-# -title_position Position of the title
218
-# -color_bar A string of "continous" or "discrete". If the mapping is continuous, whether show the legend as discrete color bar or continuous color bar
219
-# -grid_height Height of each legend grid.
220
-# -grid_width Width of each legend grid.
221
-# -border Color for legend grid borders.
222
-# -at Break values of the legend
223
-# -labels Labels corresponding to break values
224
-# -labels_gp Graphcial parameters for legend labels
225
-# -nrow If there are too many legend grids, they can be put as an array, this controls number of rows
226
-# -ncol If there are too many legend grids, they can be put as an array, this controls number of columns
227
-# -by_row When there are multiple columns for legends, whether to arrange them by rows.
228
-# -legend_height Height of the legend, only works when ``color_bar`` is ``continuous`` and ``direction`` is ``vertical``
229
-# -legend_width Width of the legend, only works when ``color_bar`` is ``continuous`` and ``direction`` is ``horizontal``
230
-# -legend_direction When ``color_bar`` is ``continuous``, should the legend be vertical or horizontal? When ``color_bar`` is ``discrete``, should the items in the legend proceed vertically or horizontally?
231
-# -param will be parsed if the parameters are specified as a list
232
-# -... pass to `grid::viewport`.
229
+# -plot Whether to plot or just return the legend object?
230
+# -... Pass to `draw,Legends-method`.
231
+# -color_bar "continous" or "discrete". It controls whether to show the discrete legend for the continuous color mapping.
232
+# -title Title of the legend, by default it is the name of the legend.
233
+# -title_gp Graphical parameters for legend title.
234
+# -title_position Position of the title. See `Legend` for all possible values.
235
+# -grid_height Height of each legend grid. Pass to `Legend`.
236
+# -grid_width Width of each legend grid. Pass to `Legend`.
237
+# -border Color for legend grid borders. Pass to `Legend`.
238
+# -at Break values of the legend. By default it is the levels in the `ColorMapping-class` object.
239
+# -labels Labels corresponding to break values.
240
+# -labels_gp Graphcial parameters for legend labels.
241
+# -labels_rot Rotation of labels.
242
+# -nrow Pass to `Legend`. It controls the layout of legend grids if they are arranged in multiple rows or columns.
243
+# -ncol Pass to `Legend`. It controls the layout of legend grids if they are arranged in multiple rows or columns.
244
+# -by_row Pass to `Legend`. It controls the order of legend grids if they are arranged in multiple rows or columns.
245
+# -legend_height Height of the legend body. It only works when ``color_bar`` is ``continuous`` and ``direction`` is ``vertical``. Pass to `Legend`.
246
+# -legend_width Width of the legend body. It only works when ``color_bar`` is ``continuous`` and ``direction`` is ``horizontal``. Pass to `Legend`.
247
+# -legend_direction When ``color_bar`` is ``continuous``, whether the legend is vertical or horizontal? Pass to `Legend`.
248
+# -param All the legend-related parameters can be specified as a single list.
233 249
 #
234 250
 # == details
235
-# A viewport is created which contains a legend title, legend grids and corresponding labels.
236
-#
237
-# This function will be improved in the future to support more types of legends.
251
+# The legend is constructed by `Legend`. 
238 252
 #
239 253
 # == value
240
-# A `grid::grob` object which contains the legend
254
+# A `Legends-class` object.
241 255
 #
242 256
 # == author
243 257
 # Zuguang Gu <z.gu@dkfz.de>
244 258
 #
245 259
 setMethod(f = "color_mapping_legend",
246 260
 	signature = "ColorMapping",
247
-	definition = function(object, ...,
248
-	plot = TRUE,
261
+	definition = function(object,
262
+	plot = TRUE, ...,
263
+	
264
+	color_bar = object@type,
265
+	
249 266
 	title = object@name,
250 267
 	title_gp = gpar(fontsize = 10, fontface = "bold"),
251 268
 	title_position = "topleft",
252
-	color_bar = object@type,
253 269
 	grid_height = unit(4, "mm"),
254 270
 	grid_width = unit(4, "mm"),
255 271
 	border = NULL,
256 272
 	at = object@levels,
257 273
 	labels = at,
258 274
 	labels_gp = gpar(fontsize = 10),
275
+	labels_rot = 0,
259 276
 	nrow = NULL,
260 277
 	ncol = 1,
261 278
 	by_row = FALSE,
262
-	legend_height = NULL, legend_width = NULL,
279
+	legend_height = NULL, 
280
+	legend_width = NULL,
263 281
 	legend_direction = c("vertical", "horizontal"),
282
+
264 283
 	param = NULL) {
265 284
 
266 285
 	e = environment()
... ...
@@ -273,8 +292,6 @@ setMethod(f = "color_mapping_legend",
273 292
 	title_gp = check_gp(title_gp)
274 293
 	labels_gp = check_gp(labels_gp)
275 294
 
276
-	# color_bar = match.arg(color_bar)
277
-
278 295
 	if(object@type == "discrete" && color_bar == "continuous") {
279 296
 		stop("'color_bar' can only be set to 'discrete' only if the color mapping is discrete")
280 297
 	}
... ...
@@ -302,17 +319,14 @@ setMethod(f = "color_mapping_legend",
302 319
 	} else {
303 320
 
304 321
 		gf = Legend(at = at, labels = labels, col_fun = object@col_fun, title = title, title_gp = title_gp, grid_height = grid_height,
305
-			grid_width = grid_width, border = border, labels_gp = labels_gp, direction = legend_direction,
322
+			grid_width = grid_width, border = border, labels_gp = labels_gp, labels_rot = labels_rot, direction = legend_direction,
306 323
 			legend_width = legend_width, legend_height = legend_height, title_position = title_position, by_row = by_row)
307 324
 
308 325
 	}
309 326
 
310 327
 	if(plot) {
311
-		pushViewport(viewport(..., width = grobWidth(gf), height = grobHeight(gf), name = paste0("legend_", object@name)))
312
-		grid.draw(gf)
313
-		popViewport()
328
+		draw(gf, ...)
314 329
 	}
315 330
 
316
-	#size = unit.c(vp_width, vp_height)
317 331
 	return(invisible(gf))
318 332
 })
... ...
@@ -125,11 +125,12 @@ Heatmap = setClass("Heatmap",
125 125
 # -rect_gp graphic parameters for drawing rectangles (for heatmap body).
126 126
 # -color_space the color space in which colors are interpolated. Only used if ``matrix`` is numeric and 
127 127
 #            ``col`` is a vector of colors. Pass to `circlize::colorRamp2`.
128
-# -border
128
+# -border border
129 129
 # -cell_fun self-defined function to add graphics on each cell. Seven parameters will be passed into 
130 130
 #           this function: ``i``, ``j``, ``x``, ``y``, ``width``, ``height``, ``fill`` which are row index,
131 131
 #           column index in ``matrix``, coordinate of the middle points in the heatmap body viewport,
132 132
 #           the width and height of the cell and the filled color. ``x``, ``y``, ``width`` and ``height`` are all `grid::unit` objects.
133
+# -layer_fun layer fun
133 134
 # -row_title title on row.
134 135
 # -row_title_side will the title be put on the left or right of the heatmap?
135 136
 # -row_title_gp graphic parameters for drawing text.
... ...
@@ -157,7 +158,6 @@ Heatmap = setClass("Heatmap",
157 158
 #                object with edges rendered, this argument will be ignored.
158 159
 # -row_dend_reorder apply reordering on rows. The value can be a logical value or a vector which contains weight 
159 160
 #               which is used to reorder rows
160
-# -row_dend_gp
161 161
 # -cluster_columns whether make cluster on columns. Same settings as ``cluster_rows``.
162 162
 # -clustering_distance_columns same setting as ``clustering_distance_rows``.
163 163
 # -clustering_method_columns method to make cluster, pass to `stats::hclust`.
... ...
@@ -167,43 +167,42 @@ Heatmap = setClass("Heatmap",
167 167
 # -column_dend_gp graphic parameters for drawling lines. Same settings as ``row_dend_gp``.
168 168
 # -column_dend_reorder apply reordering on columns. The value can be a logical value or a vector which contains weight 
169 169
 #               which is used to reorder columns
170
-# -column_dend_gp
171 170
 # -row_order order of rows. It makes it easy to adjust row order for a list of heatmaps if this heatmap 
172 171
 #      is selected as the main heatmap. Manually setting row order should turn off clustering
173 172
 # -column_order order of column. It makes it easy to adjust column order for both matrix and column annotations.
174
-# -row_labels
173