Browse code

Commit made by the Bioconductor Git-SVN bridge.

Commit id: e811f8100ef035ff75c16312b3e5112cc82d4a49

continuous legend is supported



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

z.gu authored on 13/07/2015 10:21:55
Showing 66 changed files

... ...
@@ -1,7 +1,7 @@
1 1
 Package: ComplexHeatmap
2 2
 Type: Package
3 3
 Title: Making Complex Heatmaps
4
-Version: 1.2.3
4
+Version: 1.2.4
5 5
 Date: 2015-7-11
6 6
 Author: Zuguang Gu
7 7
 Maintainer: Zuguang Gu <z.gu@dkfz.de>
... ...
@@ -1,3 +1,9 @@
1
+CHANGES in VERSION 1.2.4
2
+
3
+*  legend for continuous values can be set as continuous legends
4
+
5
+==========================================
6
+
1 7
 CHANGES in VERSION 1.2.3
2 8
 
3 9
 * `color_mapping_legend` can produce a continuous color legend
... ...
@@ -28,7 +28,8 @@ ColorMapping = setClass("ColorMapping",
28 28
 		col_fun = "function", # function to map values to colors
29 29
 		type    = "character",  # continuous or discrete
30 30
 		name    = "character",  # used to map to the dataset and taken as the title of the legend
31
-		na_col  = "character"
31
+		na_col  = "character",
32
+		color_bar = "character"
32 33
 	)
33 34
 )
34 35
 
... ...
@@ -46,6 +47,7 @@ ColorMapping = setClass("ColorMapping",
46 47
 # -enforce_breaks If it is set to `TRUE`, values of ``breaks`` will be the final break value in the legend.
47 48
 #            If it is ``FALSE``, proper breaks values will be automatically generated.
48 49
 # -na_col colors for ``NA`` values.
50
+# -color_bar if the color mapping is continuous, whether draw the legend discrete or continuous.
49 51
 #
50 52
 # == detail
51 53
 # ``colors`` and ``levels`` are used for discrete color mapping, ``col_fun`` and 
... ...
@@ -58,7 +60,8 @@ ColorMapping = setClass("ColorMapping",
58 60
 # Zuguang Gu <z.gu@dkfz.de>
59 61
 #
60 62
 ColorMapping = function(name, colors = NULL, levels = NULL, 
61
-	col_fun = NULL, breaks = NULL, enforce_breaks = FALSE, na_col = "#FFFFFF") {
63
+	col_fun = NULL, breaks = NULL, enforce_breaks = FALSE, na_col = "#FFFFFF",
64
+	color_bar = c("discrete", "continuous")) {
62 65
 
63 66
 	.Object = new("ColorMapping")
64 67
 
... ...
@@ -113,6 +116,12 @@ ColorMapping = function(name, colors = NULL, levels = NULL,
113 116
 	.Object@name = name
114 117
 	.Object@na_col = na_col
115 118
 
119
+	color_bar = match.arg(color_bar)[1]
120
+	if(.Object@type == "discrete" && color_bar == "continuous") {
121
+		stop("Continuous color bar can only be applied to continuous color mapping.")
122
+	}
123
+	.Object@color_bar = color_bar
124
+
116 125
 	return(.Object)
117 126
 }
118 127
 
... ...
@@ -213,7 +222,6 @@ setMethod(f = "map_to_colors",
213 222
 # -legend_grid_border color for legend grid borders.
214 223
 # -legend_title_gp graphic parameter for legend title.
215 224
 # -legend_label_gp graphic parameter for legend label.
216
-# -color_bar if the color mapping is continuous, whether draw the legend discrete or continuous.
217 225
 #
218 226
 # == details
219 227
 # A viewport is created which contains a legend title, legend grids and corresponding labels.
... ...
@@ -229,15 +237,12 @@ setMethod(f = "color_mapping_legend",
229 237
 	definition = function(object, ..., plot = TRUE, legend_grid_height = unit(4, "mm"),
230 238
 	legend_grid_width = unit(4, "mm"), legend_grid_border = "white",
231 239
 	legend_title_gp = gpar(fontsize = 10, fontface = "bold"),
232
-	legend_label_gp = gpar(fontsize = 10), color_bar = c("discrete", "continuous")) {
240
+	legend_label_gp = gpar(fontsize = 10)) {
233 241
 
234 242
 	legend_title_gp = check_gp(legend_title_gp)
235 243
 	legend_label_gp = check_gp(legend_label_gp)
236 244
 
237
-	color_bar = match.arg(color_bar)[1]
238
-	if(object@type == "discrete" && color_bar == "continuous") {
239
-		stop("Continuous color bar can only be applied to continuous color mapping.")
240
-	}
245
+	color_bar = object@color_bar
241 246
 
242 247
 	# add title
243 248
 	legend_title_grob = textGrob(object@name, just = c("left", "top"), gp = legend_title_gp)
... ...
@@ -178,6 +178,7 @@ Heatmap = setClass("Heatmap",
178 178
 # -width the width of the single heatmap, should be a fixed `grid::unit` object. It is used for the layout when the heatmap
179 179
 #        is appended to a list of heatmaps.
180 180
 # -show_heatmap_legend whether show heatmap legend?
181
+# -heatmap_legend_color_bar if the matrix is continuous, whether should the legend as continuous color bar as well?
181 182
 #
182 183
 # == details
183 184
 # The initialization function only applies parameter checking and fill values to each slot with proper ones.
... ...
@@ -223,7 +224,8 @@ Heatmap = function(matrix, col, name, na_col = "grey", rect_gp = gpar(col = NA),
223 224
     bottom_annotation_height = unit(5*length(bottom_annotation@anno_list), "mm"),
224 225
     km = 1, split = NULL, gap = unit(1, "mm"), 
225 226
     combined_name_fun = function(x) paste(x, collapse = "/"),
226
-    width = NULL, show_heatmap_legend = TRUE) {
227
+    width = NULL, show_heatmap_legend = TRUE,
228
+    heatmap_legend_color_bar = c("discrete", "continuous")) {
227 229
 
228 230
     .Object = new("Heatmap")
229 231
 
... ...
@@ -292,27 +294,28 @@ Heatmap = function(matrix, col, name, na_col = "grey", rect_gp = gpar(col = NA),
292 294
         .Object@matrix = matrix
293 295
     }
294 296
 
297
+    heatmap_legend_color_bar = match.arg(heatmap_legend_color_bar)[1]
295 298
     # color for main matrix
296 299
     if(ncol(matrix) > 0) {
297 300
         if(missing(col)) {
298 301
             col = default_col(matrix, main_matrix = TRUE)
299 302
         }
300 303
         if(is.function(col)) {
301
-            .Object@matrix_color_mapping = ColorMapping(col_fun = col, name = name, na_col = na_col)
304
+            .Object@matrix_color_mapping = ColorMapping(col_fun = col, name = name, na_col = na_col, color_bar = heatmap_legend_color_bar)
302 305
         } else {
303 306
             if(is.null(names(col))) {
304 307
                 if(length(col) == length(unique(matrix))) {
305 308
                     names(col) = unique(matrix)
306
-                    .Object@matrix_color_mapping = ColorMapping(colors = col, name = name, na_col = na_col)
309
+                    .Object@matrix_color_mapping = ColorMapping(colors = col, name = name, na_col = na_col, color_bar = heatmap_legend_color_bar)
307 310
                 } else if(is.numeric(matrix)) {
308 311
                     col = colorRamp2(seq(min(matrix, na.rm = TRUE), max(matrix, na.rm = TRUE), length = length(col)),
309 312
                                      col)
310
-                    .Object@matrix_color_mapping = ColorMapping(col_fun = col, name = name, na_col = na_col)
313
+                    .Object@matrix_color_mapping = ColorMapping(col_fun = col, name = name, na_col = na_col, color_bar = heatmap_legend_color_bar)
311 314
                 } else {
312 315
                     stop("`col` should have names to map to values in `mat`.")
313 316
                 }
314 317
             } else {
315
-                .Object@matrix_color_mapping = ColorMapping(colors = col, name = name, na_col = na_col)
318
+                .Object@matrix_color_mapping = ColorMapping(colors = col, name = name, na_col = na_col, color_bar = heatmap_legend_color_bar)
316 319
             }
317 320
         }
318 321
     }
... ...
@@ -42,6 +42,7 @@ HeatmapAnnotation = setClass("HeatmapAnnotation",
42 42
 # -df a data frame. Each column will be treated as a simple annotation. The data frame must have column names.
43 43
 # -name name of the heatmap annotation, optional.
44 44
 # -col a list of colors which contains color mapping to columns in ``df``. See `SingleAnnotation` for how to set colors.
45
+# -color_bar if there are continuous values in ``df``, show the legend as discrete or continuous
45 46
 # -show_legend whether show legend for each column in ``df``.
46 47
 # -... functions which define complex annotations. Values should be named arguments.
47 48
 # -which are the annotations row annotations or column annotations?
... ...
@@ -65,7 +66,8 @@ HeatmapAnnotation = setClass("HeatmapAnnotation",
65 66
 # == author
66 67
 # Zuguang Gu <z.gu@dkfz.de>
67 68
 #
68
-HeatmapAnnotation = function(df, name, col, show_legend = rep(TRUE, n_anno), ..., 
69
+HeatmapAnnotation = function(df, name, col, color_bar = rep("discrete", ncol(df)), 
70
+	show_legend = rep(TRUE, n_anno), ..., 
69 71
 	which = c("column", "row"), annotation_height = 1, annotation_width = 1, 
70 72
 	height = unit(1, "cm"), width = unit(1, "cm"), gp = gpar(col = NA),
71 73
 	gap = unit(0, "null")) {
... ...
@@ -94,16 +96,18 @@ HeatmapAnnotation = function(df, name, col, show_legend = rep(TRUE, n_anno), ...
94 96
 	    	show_legend = rep(show_legend, n_anno)
95 97
 	    }
96 98
 
99
+	    if(length(color_bar) == 1) color_bar = rep(color_bar, ncol(df))
100
+
97 101
 	    if(missing(col)) {
98 102
 	        for(i in seq_len(n_anno)) {
99
-	        	anno_list = c(anno_list, list(SingleAnnotation(name = anno_name[i], value = df[, i], which = which, show_legend = show_legend[i], gp = gp)))
103
+	        	anno_list = c(anno_list, list(SingleAnnotation(name = anno_name[i], value = df[, i], which = which, show_legend = show_legend[i], gp = gp, color_bar = color_bar[i])))
100 104
 	        }
101 105
 	    } else {
102 106
 	        for(i in seq_len(n_anno)) {
103 107
 	        	if(is.null(col[[ anno_name[i] ]])) { # if the color is not provided
104
-	        		anno_list = c(anno_list, list(SingleAnnotation(name = anno_name[i], value = df[, i], which = which, show_legend = show_legend[i], gp = gp)))
108
+	        		anno_list = c(anno_list, list(SingleAnnotation(name = anno_name[i], value = df[, i], which = which, show_legend = show_legend[i], gp = gp, color_bar = color_bar[i])))
105 109
 	        	} else {
106
-	        		anno_list = c(anno_list, list(SingleAnnotation(name = anno_name[i], value = df[, i], col = col[[ anno_name[i] ]], which = which, show_legend = show_legend[i], gp = gp)))
110
+	        		anno_list = c(anno_list, list(SingleAnnotation(name = anno_name[i], value = df[, i], col = col[[ anno_name[i] ]], which = which, show_legend = show_legend[i], gp = gp, color_bar = color_bar[i])))
107 111
 	        	}
108 112
 	        }
109 113
 	    }
... ...
@@ -55,6 +55,7 @@ SingleAnnotation = setClass("SingleAnnotation",
55 55
 # -which is the annotation a row annotation or a column annotation?
56 56
 # -show_legend if it is a simple annotation, whether show legend when making the complete heatmap.
57 57
 # -gp graphic parameters for simple annotations.
58
+# -color_bar if the color mapping is continuous, whether draw the legend discrete or continuous. Onl works for simple annotation.
58 59
 #
59 60
 # == details
60 61
 # The most simple annotation is one row or one column grids in which different colors
... ...
@@ -80,7 +81,7 @@ SingleAnnotation = setClass("SingleAnnotation",
80 81
 # Zuguang Gu <z.gu@dkfz.de>
81 82
 #
82 83
 SingleAnnotation = function(name, value, col, fun, which = c("column", "row"), 
83
-	show_legend = TRUE, gp = gpar(col = NA)) {
84
+	show_legend = TRUE, gp = gpar(col = NA), color_bar = c("discrete", "continuous")) {
84 85
 
85 86
 	.Object = new("SingleAnnotation")
86 87
 
... ...
@@ -104,15 +105,17 @@ SingleAnnotation = function(name, value, col, fun, which = c("column", "row"),
104 105
 	    }
105 106
 	}
106 107
 
108
+	color_bar = match.arg(color_bar)[1]
109
+
107 110
     if(missing(fun)) {
108 111
     	if(missing(col)) {
109 112
     		col = default_col(value)
110 113
     	}
111 114
 
112 115
     	if(is.atomic(col)) {
113
-            color_mapping = ColorMapping(name = name, colors = col)
116
+            color_mapping = ColorMapping(name = name, colors = col, color_bar = color_bar)
114 117
         } else if(is.function(col)) {
115
-            color_mapping = ColorMapping(name = name, col_fun = col)
118
+            color_mapping = ColorMapping(name = name, col_fun = col, color_bar = color_bar)
116 119
         }
117 120
 
118 121
         .Object@color_mapping = color_mapping
... ...
@@ -15,5 +15,7 @@ It is only designed for \code{+} generic method so that above three classes can
15 15
 
16 16
 }
17 17
 \examples{
18
+
19
+
18 20
 # no example
19 21
 NULL}
... ...
@@ -27,5 +27,7 @@ Zuguang Gu <z.gu@dkfz.de>
27 27
 
28 28
 }
29 29
 \examples{
30
+
31
+
30 32
 # no example
31 33
 NULL}
... ...
@@ -30,5 +30,7 @@ Zuguang Gu <z.gu@dkfz.de>
30 30
 
31 31
 }
32 32
 \examples{
33
+
34
+
33 35
 # for examples, please go to `ColorMapping` method page
34 36
 NULL}
... ...
@@ -10,7 +10,8 @@ Constructor methods for ColorMapping class
10 10
 }
11 11
 \usage{
12 12
 ColorMapping(name, colors = NULL, levels = NULL,
13
-    col_fun = NULL, breaks = NULL, enforce_breaks = FALSE, na_col = "#FFFFFF")}
13
+    col_fun = NULL, breaks = NULL, enforce_breaks = FALSE, na_col = "#FFFFFF",
14
+    color_bar = c("discrete", "continuous"))}
14 15
 \arguments{
15 16
 
16 17
   \item{name}{name for this color mapping. It is used for drawing the title of the legend.}
... ...
@@ -20,6 +21,7 @@ ColorMapping(name, colors = NULL, levels = NULL,
20 21
   \item{breaks}{breaks for the continuous color mapping. If \code{col_fun} isgenerated by \code{\link[circlize]{colorRamp2}}, \code{breaks} can be ignored.}
21 22
   \item{enforce_breaks}{If it is set to \code{\link{TRUE}}, values of \code{breaks} will be the final break value in the legend.If it is \code{FALSE}, proper breaks values will be automatically generated.}
22 23
   \item{na_col}{colors for \code{NA} values.}
24
+  \item{color_bar}{if the color mapping is continuous, whether draw the legend discrete or continuous.}
23 25
 }
24 26
 \details{
25 27
 \code{colors} and \code{levels} are used for discrete color mapping, \code{col_fun} and 
... ...
@@ -35,6 +37,8 @@ Zuguang Gu <z.gu@dkfz.de>
35 37
 
36 38
 }
37 39
 \examples{
40
+
41
+
38 42
 # discrete color mapping for characters
39 43
 cm = ColorMapping(name = "test",
40 44
     colors = c("blue", "white", "red"),
... ...
@@ -72,5 +72,7 @@ Zuguang Gu <z.gu@dkfz.de>
72 72
 
73 73
 }
74 74
 \examples{
75
+
76
+
75 77
 # for examples, please go to `Heatmap` method page
76 78
 NULL}
... ...
@@ -34,7 +34,8 @@ Heatmap(matrix, col, name, na_col = "grey", rect_gp = gpar(col = NA),
34 34
     bottom_annotation_height = unit(5*length(bottom_annotation@anno_list), "mm"),
35 35
     km = 1, split = NULL, gap = unit(1, "mm"),
36 36
     combined_name_fun = function(x) paste(x, collapse = "/"),
37
-    width = NULL, show_heatmap_legend = TRUE)}
37
+    width = NULL, show_heatmap_legend = TRUE,
38
+    heatmap_legend_color_bar = c("discrete", "continuous"))}
38 39
 \arguments{
39 40
 
40 41
   \item{matrix}{a matrix. Either numeric or character. If it is a simple vector, it will beconverted to a one-column matrix.}
... ...
@@ -85,6 +86,7 @@ Heatmap(matrix, col, name, na_col = "grey", rect_gp = gpar(col = NA),
85 86
   \item{combined_name_fun}{if the heatmap is split by rows, how to make a combined row title for each slice?The input parameter for this function is a vector which contains level names under each column in \code{split}.}
86 87
   \item{width}{the width of the single heatmap, should be a fixed \code{\link[grid]{unit}} object. It is used for the layout when the heatmapis appended to a list of heatmaps.}
87 88
   \item{show_heatmap_legend}{whether show heatmap legend?}
89
+  \item{heatmap_legend_color_bar}{if the matrix is continuous, whether should the legend as continuous color bar as well?}
88 90
 }
89 91
 \details{
90 92
 The initialization function only applies parameter checking and fill values to each slot with proper ones.
... ...
@@ -111,6 +113,8 @@ Zuguang Gu <z.gu@dkfz.de>
111 113
 
112 114
 }
113 115
 \examples{
116
+
117
+
114 118
 mat = matrix(rnorm(80, 2), 8, 10)
115 119
 mat = rbind(mat, matrix(rnorm(40, -2), 4, 10))
116 120
 rownames(mat) = letters[1:12]
... ...
@@ -29,5 +29,7 @@ Zuguang Gu <z.gu@dkfz.de>
29 29
 
30 30
 }
31 31
 \examples{
32
+
33
+
32 34
 # for examples, please go to `HeatmapAnnotation` method page
33 35
 NULL}
... ...
@@ -9,7 +9,8 @@ Constructor method for HeatmapAnnotation class
9 9
 
10 10
 }
11 11
 \usage{
12
-HeatmapAnnotation(df, name, col, show_legend = rep(TRUE, n_anno), ...,
12
+HeatmapAnnotation(df, name, col, color_bar = rep("discrete", ncol(df)),
13
+    show_legend = rep(TRUE, n_anno), ...,
13 14
     which = c("column", "row"), annotation_height = 1, annotation_width = 1,
14 15
     height = unit(1, "cm"), width = unit(1, "cm"), gp = gpar(col = NA),
15 16
     gap = unit(0, "null"))}
... ...
@@ -18,6 +19,7 @@ HeatmapAnnotation(df, name, col, show_legend = rep(TRUE, n_anno), ...,
18 19
   \item{df}{a data frame. Each column will be treated as a simple annotation. The data frame must have column names.}
19 20
   \item{name}{name of the heatmap annotation, optional.}
20 21
   \item{col}{a list of colors which contains color mapping to columns in \code{df}. See \code{\link{SingleAnnotation}} for how to set colors.}
22
+  \item{color_bar}{if there are continuous values in \code{df}, show the legend as discrete or continuous}
21 23
   \item{show_legend}{whether show legend for each column in \code{df}.}
22 24
   \item{...}{functions which define complex annotations. Values should be named arguments.}
23 25
   \item{which}{are the annotations row annotations or column annotations?}
... ...
@@ -46,6 +48,8 @@ Zuguang Gu <z.gu@dkfz.de>
46 48
 
47 49
 }
48 50
 \examples{
51
+
52
+
49 53
 df = data.frame(type = c("a", "a", "a", "b", "b", "b"))
50 54
 ha = HeatmapAnnotation(df = df)
51 55
 
... ...
@@ -68,6 +68,8 @@ Zuguang Gu <z.gu@dkfz.de>
68 68
 
69 69
 }
70 70
 \examples{
71
+
72
+
71 73
 mat = matrix(rnorm(80, 2), 8, 10)
72 74
 mat = rbind(mat, matrix(rnorm(40, -2), 4, 10))
73 75
 rownames(mat) = letters[1:12]
... ...
@@ -27,7 +27,11 @@ Zuguang Gu <z.gu@dkfz.de>
27 27
 
28 28
 }
29 29
 \section{Detailes}{
30
+
31
+
30 32
 There is no public constructor method for the \code{\link{HeatmapList-class}}.}
31 33
 \examples{
34
+
35
+
32 36
 # no example
33 37
 NULL}
... ...
@@ -39,5 +39,7 @@ Zuguang Gu <z.gu@dkfz.de>
39 39
 
40 40
 }
41 41
 \examples{
42
+
43
+
42 44
 # for examples, please go to `SingleAnnotation` method page
43 45
 NULL}
... ...
@@ -10,7 +10,7 @@ Constructor method for SingleAnnotation class
10 10
 }
11 11
 \usage{
12 12
 SingleAnnotation(name, value, col, fun, which = c("column", "row"),
13
-    show_legend = TRUE, gp = gpar(col = NA))}
13
+    show_legend = TRUE, gp = gpar(col = NA), color_bar = c("discrete", "continuous"))}
14 14
 \arguments{
15 15
 
16 16
   \item{name}{name for this annotation.}
... ...
@@ -20,6 +20,7 @@ SingleAnnotation(name, value, col, fun, which = c("column", "row"),
20 20
   \item{which}{is the annotation a row annotation or a column annotation?}
21 21
   \item{show_legend}{if it is a simple annotation, whether show legend when making the complete heatmap.}
22 22
   \item{gp}{graphic parameters for simple annotations.}
23
+  \item{color_bar}{if the color mapping is continuous, whether draw the legend discrete or continuous. Onl works for simple annotation.}
23 24
 }
24 25
 \details{
25 26
 The most simple annotation is one row or one column grids in which different colors
... ...
@@ -48,6 +49,8 @@ Zuguang Gu <z.gu@dkfz.de>
48 49
 
49 50
 }
50 51
 \examples{
52
+
53
+
51 54
 # discrete character
52 55
 SingleAnnotation(name = "test", value = c("a", "a", "a", "b", "b", "b"))
53 56
 SingleAnnotation(name = "test", value = c("a", "a", "a", "b", "b", "b"), 
... ...
@@ -31,6 +31,8 @@ Zuguang Gu <z.gu@dkfz.de>
31 31
 
32 32
 }
33 33
 \examples{
34
+
35
+
34 36
 mat = matrix(rnorm(80, 2), 8, 10)
35 37
 mat = rbind(mat, matrix(rnorm(40, -2), 4, 10))
36 38
 rownames(mat) = letters[1:12]
... ...
@@ -28,6 +28,8 @@ Zuguang Gu <z.gu@dkfz.de>
28 28
 
29 29
 }
30 30
 \examples{
31
+
32
+
31 33
 mat = matrix(rnorm(80, 2), 8, 10)
32 34
 mat = rbind(mat, matrix(rnorm(40, -2), 4, 10))
33 35
 rownames(mat) = letters[1:12]
... ...
@@ -28,6 +28,8 @@ Zuguang Gu <z.gu@dkfz.de>
28 28
 
29 29
 }
30 30
 \examples{
31
+
32
+
31 33
 mat = matrix(rnorm(80, 2), 8, 10)
32 34
 mat = rbind(mat, matrix(rnorm(40, -2), 4, 10))
33 35
 rownames(mat) = letters[1:12]
... ...
@@ -28,6 +28,8 @@ Zuguang Gu <z.gu@dkfz.de>
28 28
 
29 29
 }
30 30
 \examples{
31
+
32
+
31 33
 mat = matrix(rnorm(80, 2), 8, 10)
32 34
 mat = rbind(mat, matrix(rnorm(40, -2), 4, 10))
33 35
 rownames(mat) = letters[1:12]
... ...
@@ -31,6 +31,8 @@ Zuguang Gu <z.gu@dkfz.de>
31 31
 
32 32
 }
33 33
 \examples{
34
+
35
+
34 36
 f = anno_barplot(rnorm(10))
35 37
 grid.newpage(); f(1:10)
36 38
 
... ...
@@ -32,6 +32,8 @@ Zuguang Gu <z.gu@dkfz.de>
32 32
 
33 33
 }
34 34
 \examples{
35
+
36
+
35 37
 mat = matrix(rnorm(32), nrow = 4)
36 38
 f = anno_boxplot(mat)
37 39
 grid.newpage(); f(1:8)
... ...
@@ -28,6 +28,8 @@ Zuguang Gu <z.gu@dkfz.de>
28 28
 
29 29
 }
30 30
 \examples{
31
+
32
+
31 33
 mat = matrix(rnorm(32), nrow = 4)
32 34
 f = anno_density(mat)
33 35
 grid.newpage(); f(1:8)
... ...
@@ -26,6 +26,8 @@ Zuguang Gu <z.gu@dkfz.de>
26 26
 
27 27
 }
28 28
 \examples{
29
+
30
+
29 31
 mat = matrix(rnorm(32), nrow = 4)
30 32
 f = anno_histogram(mat)
31 33
 grid.newpage(); f(1:8)
... ...
@@ -33,5 +33,7 @@ Zuguang Gu <z.gu@dkfz.de>
33 33
 
34 34
 }
35 35
 \examples{
36
+
37
+
36 38
 f = anno_points(rnorm(10))
37 39
 grid.newpage(); f(1:10)}
... ...
@@ -29,6 +29,8 @@ Zuguang Gu <z.gu@dkfz.de>
29 29
 
30 30
 }
31 31
 \examples{
32
+
33
+
32 34
 mat = matrix(rnorm(100), 10)
33 35
 colnames(mat) = letters[1:10]
34 36
 rownames(mat) = LETTERS[1:10]
... ...
@@ -33,5 +33,7 @@ Zuguang Gu <z.gu@dkfz.de>
33 33
 
34 34
 }
35 35
 \examples{
36
+
37
+
36 38
 # no example for this internal method
37 39
 NULL}
... ...
@@ -13,7 +13,7 @@ Draw legend based on color mapping
13 13
 \S4method{color_mapping_legend}{ColorMapping}(object, ..., plot = TRUE, legend_grid_height = unit(4, "mm"),
14 14
     legend_grid_width = unit(4, "mm"), legend_grid_border = "white",
15 15
     legend_title_gp = gpar(fontsize = 10, fontface = "bold"),
16
-    legend_label_gp = gpar(fontsize = 10), color_bar = c("discrete", "continuous"))}
16
+    legend_label_gp = gpar(fontsize = 10))}
17 17
 \arguments{
18 18
 
19 19
   \item{object}{a \code{\link{ColorMapping-class}} object.}
... ...
@@ -24,7 +24,6 @@ Draw legend based on color mapping
24 24
   \item{legend_grid_border}{color for legend grid borders.}
25 25
   \item{legend_title_gp}{graphic parameter for legend title.}
26 26
   \item{legend_label_gp}{graphic parameter for legend label.}
27
-  \item{color_bar}{if the color mapping is continuous, whether draw the legend discrete or continuous.}
28 27
 }
29 28
 \details{
30 29
 A viewport is created which contains a legend title, legend grids and corresponding labels.
... ...
@@ -39,6 +38,8 @@ Zuguang Gu <z.gu@dkfz.de>
39 38
 
40 39
 }
41 40
 \examples{
41
+
42
+
42 43
 # discrete color mapping for characters
43 44
 cm = ColorMapping(name = "test",
44 45
     colors = c("blue", "white", "red"),
... ...
@@ -31,5 +31,7 @@ Zuguang Gu <z.gu@dkfz.de>
31 31
 
32 32
 }
33 33
 \examples{
34
+
35
+
34 36
 df = data.frame(type = c("a", "a", "a", "b", "b", "b"))
35 37
 ha = rowAnnotation(df = df)}
... ...
@@ -28,4 +28,6 @@ Zuguang Gu <z.gu@dkfz.de>
28 28
 
29 29
 }
30 30
 \examples{
31
+
32
+
31 33
 # no example for this internal method}
... ...
@@ -24,4 +24,6 @@ Zuguang Gu <z.gu@dkfz.de>
24 24
 
25 25
 }
26 26
 \examples{
27
+
28
+
27 29
 # no example for this internal method}
... ...
@@ -20,6 +20,8 @@ This function is only for internal use.
20 20
 
21 21
 }
22 22
 \section{Detials}{
23
+
24
+
23 25
 This function is only for internal use.}
24 26
 \value{
25 27
 A \code{\link[grid]{unit}} object.
... ...
@@ -30,4 +32,6 @@ Zuguang Gu <z.gu@dkfz.de>
30 32
 
31 33
 }
32 34
 \examples{
35
+
36
+
33 37
 # no example for this internal method}
... ...
@@ -28,4 +28,6 @@ Zuguang Gu <z.gu@dkfz.de>
28 28
 
29 29
 }
30 30
 \examples{
31
+
32
+
31 33
 # no example for this internal method}
... ...
@@ -30,6 +30,8 @@ Zuguang Gu <z.gu@dkfz.de>
30 30
 
31 31
 }
32 32
 \examples{
33
+
34
+
33 35
 mat = matrix(rnorm(40), nr = 4, ncol = 10)
34 36
 rownames(mat) = letters[1:4]
35 37
 colnames(mat) = letters[1:10]
... ...
@@ -31,6 +31,8 @@ Zuguang Gu <z.gu@dkfz.de>
31 31
 
32 32
 }
33 33
 \examples{
34
+
35
+
34 36
 mat = matrix(rnorm(80, 2), 8, 10)
35 37
 mat = rbind(mat, matrix(rnorm(40, -2), 4, 10))
36 38
 rownames(mat) = letters[1:12]
... ...
@@ -30,6 +30,8 @@ Zuguang Gu <z.gu@dkfz.de>
30 30
 
31 31
 }
32 32
 \examples{
33
+
34
+
33 35
 df = data.frame(type = c("a", "a", "a", "b", "b", "b"))
34 36
 ha = HeatmapAnnotation(df = df)
35 37
 grid.newpage(); draw(ha, 1:6)
... ...
@@ -33,6 +33,8 @@ Zuguang Gu <z.gu@dkfz.de>
33 33
 
34 34
 }
35 35
 \examples{
36
+
37
+
36 38
 mat = matrix(rnorm(80, 2), 8, 10)
37 39
 mat = rbind(mat, matrix(rnorm(40, -2), 4, 10))
38 40
 rownames(mat) = letters[1:12]
... ...
@@ -31,6 +31,8 @@ Zuguang Gu <z.gu@dkfz.de>
31 31
 
32 32
 }
33 33
 \examples{
34
+
35
+
34 36
 anno = SingleAnnotation(name = "test", value = c("a", "a", "a", "b", "b", "b"))
35 37
 grid.newpage(); draw(anno, 1:5)
36 38
 grid.newpage(); draw(anno, c(1, 4, 3, 5, 2))
... ...
@@ -34,5 +34,7 @@ Zuguang Gu <z.gu@dkfz.de>
34 34
 
35 35
 }
36 36
 \examples{
37
+
38
+
37 39
 # no example for this internal method
38 40
 NULL}
... ...
@@ -32,5 +32,7 @@ Zuguang Gu <z.gu@dkfz.de>
32 32
 
33 33
 }
34 34
 \examples{
35
+
36
+
35 37
 # no example for this internal method
36 38
 NULL}
... ...
@@ -35,5 +35,7 @@ Zuguang Gu <z.gu@dkfz.de>
35 35
 
36 36
 }
37 37
 \examples{
38
+
39
+
38 40
 # no example for this internal method
39 41
 NULL}
... ...
@@ -42,5 +42,7 @@ Zuguang Gu <z.gu@dkfz.de>
42 42
 
43 43
 }
44 44
 \examples{
45
+
46
+
45 47
 # no example for this internal method
46 48
 NULL}
... ...
@@ -36,5 +36,7 @@ Zuguang Gu <z.gu@dkfz.de>
36 36
 
37 37
 }
38 38
 \examples{
39
+
40
+
39 41
 # no example for this internal method
40 42
 NULL}
... ...
@@ -32,5 +32,7 @@ Zuguang Gu <z.gu@dkfz.de>
32 32
 
33 33
 }
34 34
 \examples{
35
+
36
+
35 37
 # no example for this internal method
36 38
 NULL}
... ...
@@ -30,5 +30,7 @@ Zuguang Gu <z.gu@dkfz.de>
30 30
 
31 31
 }
32 32
 \examples{
33
+
34
+
33 35
 # no example for this internal method
34 36
 NULL}
... ...
@@ -33,5 +33,7 @@ Zuguang Gu <z.gu@dkfz.de>
33 33
 
34 34
 }
35 35
 \examples{
36
+
37
+
36 38
 # no example for this internal method
37 39
 NULL}
... ...
@@ -31,5 +31,7 @@ Zuguang Gu <z.gu@dkfz.de>
31 31
 
32 32
 }
33 33
 \examples{
34
+
35
+
34 36
 # no example for this internal method
35 37
 NULL}
... ...
@@ -30,5 +30,7 @@ Zuguang Gu <z.gu@dkfz.de>
30 30
 
31 31
 }
32 32
 \examples{
33
+
34
+
33 35
 # no example for this internal method
34 36
 NULL}
... ...
@@ -34,6 +34,8 @@ Zuguang Gu <z.gu@dkfz.de>
34 34
 
35 35
 }
36 36
 \examples{
37
+
38
+
37 39
 hc = hclust(dist(USArrests[1:5, ]))
38 40
 dend = as.dendrogram(hc)
39 41
 
... ...
@@ -30,5 +30,7 @@ Zuguang Gu <z.gu@dkfz.de>
30 30
 
31 31
 }
32 32
 \examples{
33
+
34
+
33 35
 # no example for this internal method
34 36
 NULL}
... ...
@@ -30,5 +30,7 @@ Zuguang Gu <z.gu@dkfz.de>
30 30
 
31 31
 }
32 32
 \examples{
33
+
34
+
33 35
 # no example for this internal method
34 36
 NULL}
... ...
@@ -33,5 +33,7 @@ Zuguang Gu <z.gu@dkfz.de>
33 33
 
34 34
 }
35 35
 \examples{
36
+
37
+
36 38
 # no example for this internal method
37 39
 NULL}
... ...
@@ -59,5 +59,7 @@ Zuguang Gu <z.gu@dkfz.de>
59 59
 
60 60
 }
61 61
 \examples{
62
+
63
+
62 64
 # no example for this internal method
63 65
 NULL}
... ...
@@ -32,5 +32,7 @@ Zuguang Gu <z.gu@dkfz.de>
32 32
 
33 33
 }
34 34
 \examples{
35
+
36
+
35 37
 # no example for this internal method
36 38
 NULL}
... ...
@@ -29,6 +29,8 @@ Zuguang Gu <z.gu@dkfz.de>
29 29
 
30 30
 }
31 31
 \examples{
32
+
33
+
32 34
 # discrete color mapping for characters
33 35
 cm = ColorMapping(name = "test",
34 36
     colors = c("blue", "white", "red"),
... ...
@@ -25,5 +25,7 @@ This function returns no value.
25 25
 
26 26
 }
27 27
 \examples{
28
+
29
+
28 30
 # no example 
29 31
 NULL}
... ...
@@ -46,6 +46,8 @@ Zuguang Gu <z.gu@dkfz.de>
46 46
 
47 47
 }
48 48
 \examples{
49
+
50
+
49 51
 df = data.frame(matrix(rnorm(40), nrow = 10, dimnames = list(letters[1:10], letters[1:4])),
50 52
                 large = runif(10)*100,
51 53
                 t1 = sample(letters[1:3], 10, replace = TRUE),
... ...
@@ -37,5 +37,7 @@ Zuguang Gu <z.gu@dkfz.de>
37 37
 
38 38
 }
39 39
 \examples{
40
+
41
+
40 42
 # no example for this internal method
41 43
 NULL}
... ...
@@ -25,5 +25,7 @@ This function returns no value.
25 25
 
26 26
 }
27 27
 \examples{
28
+
29
+
28 30
 # no example 
29 31
 NULL}
... ...
@@ -31,5 +31,7 @@ Zuguang Gu <z.gu@dkfz.de>
31 31
 
32 32
 }
33 33
 \examples{
34
+
35
+
34 36
 df = data.frame(type = c("a", "a", "a", "b", "b", "b"))
35 37
 ha = columnAnnotation(df = df)}
... ...
@@ -30,5 +30,7 @@ Zuguang Gu <z.gu@dkfz.de>
30 30
 
31 31
 }
32 32
 \examples{
33
+
34
+
33 35
 # no example for this internal method
34 36
 NULL}
... ...
@@ -28,6 +28,8 @@ Zuguang Gu <z.gu@dkfz.de>
28 28
 
29 29
 }
30 30
 \examples{
31
+
32
+
31 33
 mat = matrix(rnorm(80, 2), 8, 10)
32 34
 mat = rbind(mat, matrix(rnorm(40, -2), 4, 10))
33 35
 rownames(mat) = letters[1:12]
... ...
@@ -24,4 +24,6 @@ This function returns no value.
24 24
 
25 25
 }
26 26
 \author{
27
+
28
+
27 29
 Zuguang Gu <z.gu@dkfz.de>}
... ...
@@ -657,16 +657,6 @@ ht2 = Heatmap(mat, name = "ht2", column_title = "Heatmap 2", show_heatmap_legend
657 657
 ht1 + ht2
658 658
 ```
659 659
 
660
-**ComplexHeatmap** only generates legends for heatmaps and simple annotations. Self-defined legends
661
-can be passed by `annotation_legend_list` as a list of `grob` objects.
662
-
663
-```{r self_defined_annotation_legend, fig.width = 10}
664
-ha = HeatmapAnnotation(points = anno_points(rnorm(10)))
665
-ht2 = Heatmap(mat, name = "ht2", column_title = "Heatmap 2", top_annotation = ha, show_heatmap_legend = FALSE)
666
-lgd = legendGrob(c("dots"), pch = 16)
667
-draw(ht1 + ht2, annotation_legend_list = list(lgd))
668
-```
669
-
670 660
 Graphic parameters for legends for simple annotations can be set. Actually these arguments are passed
671 661
 to `color_mapping_legend()` in `ColorMapping` class.
672 662
 
... ...
@@ -687,13 +677,29 @@ draw(ht1 + ht2, heatmap_legend_list = list(color_mapping_legend(cm, plot = FALSE
687 677
 ```
688 678
 
689 679
 Default legend style for continuous color mapping is created by first calculating break values for continuous values and 
690
-then drawing these discrete break values as discrete legend grids. However, you can self construct a continuous
691
-legend by `ColorMapping` class.
680
+then drawing these discrete break values as discrete legend grids. You can switch to continuous legends both for heatmap legend
681
+and annotation legends.
692 682
 
693 683
 ```{r self_define_heatmap_continuous_legend, fig.width = 10}
694
-draw(ht1 + ht2, heatmap_legend_list = list(color_mapping_legend(cm, plot = FALSE, color_bar = "continuous")))
684
+df = data.frame(type = runif(10))
685
+ha = HeatmapAnnotation(df = df, color_bar = "continuous")
686
+ht1 = Heatmap(mat, name = "ht1", column_title = "Heatmap 1", top_annotation = ha)
687
+ht2 = Heatmap(mat, name = "ht2", col = col_fun, column_title = "Heatmap 2", 
688
+    heatmap_legend_color_bar = "continuous")
689
+draw(ht1 + ht2)
695 690
 ```
696 691
 
692
+**ComplexHeatmap** only generates legends for heatmaps and simple annotations. Self-defined legends
693
+can be passed by 1heatmap_legend_list` and `annotation_legend_list` as a list of `grob` objects.
694
+
695
+```{r self_defined_annotation_legend, fig.width = 10}
696
+ha = HeatmapAnnotation(points = anno_points(rnorm(10)))
697
+ht2 = Heatmap(mat, name = "ht2", column_title = "Heatmap 2", top_annotation = ha, show_heatmap_legend = FALSE)
698
+lgd = legendGrob(c("dots"), pch = 16)
699
+draw(ht1 + ht2, annotation_legend_list = list(lgd))
700
+```
701
+
702
+
697 703
 ### Gaps between heatmaps
698 704
 
699 705
 The gaps between heatmaps can be set by `gap` argument with a `unit` object.