Browse code

densithHeatmap(): col now can be a function

Zuguang Gu authored on 26/09/2019 08:52:20
Showing3 changed files

... ...
@@ -6,6 +6,7 @@ CHANGES in VERSION 2.1.0
6 6
 * `draw_legend()`: legends for annotations with the same names are merged
7 7
 * `densityHeatmap()`: `ylim` works as it is expected.
8 8
 * add `cluster_row_slices` and `cluster_column_slices` to `draw,HeatmapList-method()`
9
+* `densityHeatmap()`: `col` can be set as a function
9 10
 
10 11
 ========================
11 12
 
... ...
@@ -3340,6 +3340,7 @@ anno_zoom = function(align_to, panel_fun = function(index, nm = NULL) { grid.rec
3340 3340
 			if(n_boxes == 1) {
3341 3341
 				h = data.frame(bottom = .scale[1] - extend[1], top = .scale[2] + extend[2])
3342 3342
 			} else {
3343
+				size = as.numeric(size)
3343 3344
 				gap = convertHeight(gap, "native", valueOnly = TRUE)
3344 3345
 				box_height = size/sum(size) * (1 + sum(extend) - sum(gap[1:(n_boxes-1)]))
3345 3346
 				h = data.frame(
... ...
@@ -3489,6 +3490,7 @@ anno_zoom = function(align_to, panel_fun = function(index, nm = NULL) { grid.rec
3489 3490
 			if(n_boxes == 1) {
3490 3491
 				h = data.frame(left = .scale[1] - extend[1], right = .scale[2] + extend[2])
3491 3492
 			} else {
3493
+				size = as.numeric(size)
3492 3494
 				gap = convertWidth(gap, "native", valueOnly = TRUE)
3493 3495
 				box_width = size/sum(size) * (1 + sum(extend) - sum(gap[1:(n_boxes-1)]))
3494 3496
 				h = data.frame(
... ...
@@ -151,7 +151,11 @@ densityHeatmap = function(data,
151 151
 		}
152 152
 	}
153 153
 
154
-	col = colorRamp2(seq(0, max(mat, na.rm = TRUE), length = length(col)), col, space = color_space)
154
+	if(inherits(col, "function")) {
155
+		col = col(mat)
156
+	} else {
157
+		col = colorRamp2(seq(0, max(mat, na.rm = TRUE), length = length(col)), col, space = color_space)
158
+	}
155 159
 
156 160
 	bb = grid.pretty(c(min_x, max_x))
157 161
 	ht = Heatmap(mat, col = col, name = "density",