Browse code

udpate

jokergoo authored on 11/10/2018 14:44:34
Showing9 changed files

... ...
@@ -2656,7 +2656,9 @@ row_anno_link = function(...) {
2656 2656
 # only allow for one-column/one-row heamtap
2657 2657
 # discrete: barplot; continuous: boxplot (maybe also barplot, e.g. pct overlap)
2658 2658
 anno_summary = function(which = c("column", "row"), border = TRUE, bar_width = 0.8, 
2659
-	axis = TRUE, axis_param = default_axis_param(which), 
2659
+	axis = TRUE, axis_param = default_axis_param(which),
2660
+	ylim = NULL, extend = 0.05, outline = TRUE, box_width = 0.6,
2661
+	pch = 1, size = unit(2, "mm"), gp = gpar(),
2660 2662
 	width = NULL, height = NULL, ...) {
2661 2663
 
2662 2664
 	if(is.null(.ENV$current_annotation_which)) {
... ...
@@ -2668,7 +2670,11 @@ anno_summary = function(which = c("column", "row"), border = TRUE, bar_width = 0
2668 2670
 	anno_size = anno_width_and_height(which, width, height, unit(2, "cm"))
2669 2671
 
2670 2672
 	axis_param = validate_axis_param(axis_param, which)
2671
-	axis_grob = if(axis) construct_axis_grob(axis_param, which, c(0, 1)) else NULL
2673
+	if(is.null(ylim)) {
2674
+		axis_grob = if(axis) construct_axis_grob(axis_param, which, c(0, 1)) else NULL
2675
+	} else {
2676
+		axis_grob = if(axis) construct_axis_grob(axis_param, which, ylim) else NULL
2677
+	}
2672 2678
 
2673 2679
 	row_fun = function(index) {
2674 2680
 		ht = get("object", envir = parent.frame(7))
... ...
@@ -2691,7 +2697,7 @@ anno_summary = function(which = c("column", "row"), border = TRUE, bar_width = 0
2691 2697
 			if(border) grid.rect(gp = gpar(fill = "transparent"))
2692 2698
 			popViewport()
2693 2699
 		} else {
2694
-			stop_wrap("`anno_summary()` currently only supports discrete matrix.")
2700
+			
2695 2701
 		}
2696 2702
 	}
2697 2703
 	column_fun = function(index) {
... ...
@@ -2702,6 +2708,9 @@ anno_summary = function(which = c("column", "row"), border = TRUE, bar_width = 0
2702 2708
 		ng = length(order_list)
2703 2709
 
2704 2710
 		if(cm@type == "discrete") {
2711
+			if(!is.null(ylim)) {
2712
+				stop_wrap("For discrete matrix, `ylim` is not allowed to set. It is always c(0, 1).")
2713
+			}
2705 2714
 			tl = lapply(order_list, function(od) table(mat[od, 1]))
2706 2715
 			tl = lapply(tl, function(x) x/sum(x))
2707 2716
 
... ...
@@ -2715,7 +2724,39 @@ anno_summary = function(which = c("column", "row"), border = TRUE, bar_width = 0
2715 2724
 			if(border) grid.rect(gp = gpar(fill = "transparent"))
2716 2725
 			popViewport()
2717 2726
 		} else {
2718
-			stop_wrap("`anno_summary()` currently only supports discrete matrix.")
2727
+			vl = lapply(order_list, function(od) mat[od, 1])
2728
+			nv = length(vl)
2729
+			if(is.null(ylim)) {
2730
+				if(!outline) {
2731
+					boxplot_stats = boxplot(vl, plot = FALSE)$stats
2732
+					data_scale = range(boxplot_stats)
2733
+				} else {
2734
+					data_scale = range(vl, na.rm = TRUE)
2735
+				}
2736
+			} else {
2737
+				data_scale = ylim
2738
+			}
2739
+			data_scale = data_scale + c(-extend, extend)*(data_scale[2] - data_scale[1])
2740
+
2741
+			if(is.null(ylim)) {
2742
+				axis_param = validate_axis_param(axis_param, which)
2743
+				axis_grob = if(axis) construct_axis_grob(axis_param, which, data_scale) else NULL
2744
+			}
2745
+
2746
+			gp = recycle_gp(gp, nv)
2747
+			if(length(pch) == 1) pch = rep(pch, nv)
2748
+			if(length(size) == 1) size = rep(size, nv)
2749
+
2750
+			pushViewport(viewport(xscale = c(0.5, ng+0.5), yscale = data_scale))
2751
+			for(i in 1:ng) {
2752
+				x = i
2753
+				v = vl[[i]]
2754
+				grid.boxplot(v, pos = x, box_width = box_width, gp = subset_gp(gp, i),
2755
+					pch = pch, size = size)
2756
+			}
2757
+			if(axis) grid.draw(axis_grob)
2758
+			if(border) grid.rect(gp = gpar(fill = "transparent"))
2759
+			popViewport()
2719 2760
 		}
2720 2761
 	}
2721 2762
 
... ...
@@ -2731,7 +2772,8 @@ anno_summary = function(which = c("column", "row"), border = TRUE, bar_width = 0
2731 2772
 		which = which,
2732 2773
 		width = width,
2733 2774
 		height = height,
2734
-		var_import = list(bar_width, border, axis, axis_grob),
2775
+		var_import = list(bar_width, border, axis, axis_grob, axis_param, which, ylim, extend, 
2776
+			outline, box_width, pch, size, gp),
2735 2777
 		n = 1,
2736 2778
 		show_name = FALSE
2737 2779
 	)
... ...
@@ -330,7 +330,8 @@ setMethod(f = "draw",
330 330
     split = NULL,
331 331
     row_km = km,
332 332
     row_split = split,
333
-    heatmap_body_height = NULL,
333
+    height = NULL,
334
+    heatmap_height = NULL,
334 335
 
335 336
     column_gap = NULL,
336 337
     cluster_columns = NULL,
... ...
@@ -343,7 +344,8 @@ setMethod(f = "draw",
343 344
     column_order = NULL,
344 345
     column_km = NULL,
345 346
     column_split = NULL,
346
-    heatmap_body_width = NULL,
347
+    width = NULL,
348
+    heatmap_width = NULL,
347 349
 
348 350
     ### global setting
349 351
     heatmap_row_names_gp = NULL,
... ...
@@ -402,10 +404,37 @@ setMethod(f = "draw",
402 404
         }
403 405
         if(direction == "horizontal") {
404 406
             nr = ob[1]
405
-            object = object + Heatmap(matrix(ncol = 0, nrow = nr))
407
+            max_height = max(do.call("unit.c", lapply(object@ht_list, function(ha) {
408
+                h = height(ha)
409
+                if(is_abs_unit(h)) {
410
+                    convertHeight(h, "mm")
411
+                } else {
412
+                    unit(0, "mm")
413
+                }
414
+            })))
415
+            max_height = convertHeight(max_height, "mm")
416
+            if(max_height[[1]] == 0) {
417
+                object = object + Heatmap(matrix(ncol = 0, nrow = nr))
418
+            } else {
419
+                object = object + Heatmap(matrix(ncol = 0, nrow = nr), height = max_height)
420
+            }
421
+            
406 422
         } else {
407 423
             nc = ob[1]
408
-            object = object %v% Heatmap(matrix(nrow = 0, ncol = nc))
424
+            max_width = max(do.call("unit.c", lapply(object@ht_list, function(ha) {
425
+                w = width(ha)
426
+                if(is_abs_unit(w)) {
427
+                    convertWidth(w, "mm")
428
+                } else {
429
+                    unit(0, "mm")
430
+                }
431
+            })))
432
+            max_width = convertWidth(max_width, "mm")
433
+            if(max_width[[1]] == 0) {
434
+                object = object %v% Heatmap(matrix(nrow = 0, ncol = nc))
435
+            } else {
436
+                object = object %v% Heatmap(matrix(nrow = 0, ncol = nc), width = max_width)
437
+            }
409 438
         }
410 439
     }
411 440
 
... ...
@@ -463,7 +492,8 @@ setMethod(f = "draw",
463 492
         row_order = row_order,
464 493
         row_km = row_km,
465 494
         row_split = row_split,
466
-        heatmap_body_height = heatmap_body_height,
495
+        height = height,
496
+        heatmap_height = heatmap_height,
467 497
 
468 498
         column_gap = column_gap,
469 499
         cluster_columns = cluster_columns,
... ...
@@ -476,7 +506,8 @@ setMethod(f = "draw",
476 506
         column_order = column_order,
477 507
         column_km = column_km,
478 508
         column_split = column_split,
479
-        heatmap_body_width = heatmap_body_width
509
+        width = width,
510
+        heatmap_width = heatmap_width
480 511
     )
481 512
 
482 513
     layout = grid.layout(nrow = length(HEATMAP_LIST_LAYOUT_COLUMN_COMPONENT), 
... ...
@@ -188,7 +188,7 @@ setMethod(f = "adjust_heatmap_list",
188 188
             max_left_component_width = unit(0, "mm")
189 189
             if(inherits(object@ht_list[[1]], "Heatmap")) {
190 190
                 ht_first = object@ht_list[[1]]
191
-                max_left_component_width = sum(component_width(ht_first, c("row_names_left", "row_dend_left", "row_anno_left")))
191
+                max_left_component_width = sum(component_width(ht_first, c("row_names_left", "row_dend_left", "row_anno_left", "row_title_left")))
192 192
                 u = unit(0, "mm")
193 193
                 if(!is.null(ht_first@top_annotation)) {
194 194
                     u = unit.c(u, ht_first@top_annotation@extended[2])
... ...
@@ -205,7 +205,7 @@ setMethod(f = "adjust_heatmap_list",
205 205
             max_right_component_width = unit(0, "mm")
206 206
             if(inherits(object@ht_list[[ length(object@ht_list) ]], "Heatmap")) {
207 207
                 ht_last = object@ht_list[[ length(object@ht_list) ]]
208
-                max_right_component_width = sum(component_width(ht_last, c("row_names_right", "row_dend_right", "row_anno_right")))
208
+                max_right_component_width = sum(component_width(ht_last, c("row_names_right", "row_dend_right", "row_anno_right", "row_title_right")))
209 209
                 u = unit(0, "mm")
210 210
                 if(!is.null(ht_last@top_annotation)) {
211 211
                     u = unit.c(u, ht_last@top_annotation@extended[4])
... ...
@@ -250,7 +250,7 @@ setMethod(f = "adjust_heatmap_list",
250 250
 
251 251
         max_left_component_width = max(do.call("unit.c", lapply(object@ht_list, function(ht) {
252 252
             if(inherits(ht, "Heatmap")) {
253
-                sum(component_width(ht, c("row_dend_left", "row_names_left", "row_anno_left")))   
253
+                sum(component_width(ht, c("row_dend_left", "row_names_left", "row_anno_left", "row_title_left")))   
254 254
             } else {
255 255
                 unit(0, "mm")
256 256
             }
... ...
@@ -258,7 +258,7 @@ setMethod(f = "adjust_heatmap_list",
258 258
         max_left_component_width = convertWidth(max_left_component_width, "mm")
259 259
         max_right_component_width = max(do.call("unit.c", lapply(object@ht_list, function(ht) {
260 260
             if(inherits(ht, "Heatmap")) {
261
-                sum(component_width(ht, c("row_dend_right", "row_names_right", "row_anno_right")))
261
+                sum(component_width(ht, c("row_dend_right", "row_names_right", "row_anno_right", "row_title_right")))
262 262
             } else {
263 263
                 unit(0, "mm")
264 264
             }
... ...
@@ -389,7 +389,7 @@ setMethod(f = "adjust_heatmap_list",
389 389
             max_top_component_height = unit(0, "mm")
390 390
             if(inherits(object@ht_list[[1]], "Heatmap")) {
391 391
                 ht_first = object@ht_list[[1]]
392
-                max_top_component_height = sum(component_height(ht_first, c("column_names_top", "column_dend_top", "column_anno_top")))
392
+                max_top_component_height = sum(component_height(ht_first, c("column_names_top", "column_dend_top", "column_anno_top", "column_title_top")))
393 393
                 u = unit(0, "mm")
394 394
                 if(!is.null(ht_first@left_annotation)) {
395 395
                     u = unit.c(u, ht_first@left_annotation@extended[3])
... ...
@@ -406,7 +406,7 @@ setMethod(f = "adjust_heatmap_list",
406 406
             max_bottom_component_height = unit(0, "mm")
407 407
             if(inherits(object@ht_list[[ length(object@ht_list) ]], "Heatmap")) {
408 408
                 ht_last = object@ht_list[[ length(object@ht_list) ]]
409
-                max_bottom_component_height = sum(component_height(ht_last, c("column_names_bottom", "column_dend_bottom", "column_anno_bottom")))
409
+                max_bottom_component_height = sum(component_height(ht_last, c("column_names_bottom", "column_dend_bottom", "column_anno_bottom", "column_title_bottom")))
410 410
                 u = unit(0, "mm")
411 411
                 if(!is.null(ht_last@left_annotation)) {
412 412
                     u = unit.c(u, ht_last@left_annotation@extended[1])
... ...
@@ -103,7 +103,8 @@ setMethod(f = "make_layout",
103 103
     row_order = NULL,
104 104
     row_km = NULL,
105 105
     row_split = NULL,
106
-    heatmap_body_height = NULL,
106
+    height = NULL,
107
+    heatmap_height = NULL,
107 108
 
108 109
     column_gap = NULL,
109 110
     cluster_columns = NULL,
... ...
@@ -116,7 +117,8 @@ setMethod(f = "make_layout",
116 117
     column_order = NULL,
117 118
     column_km = NULL,
118 119
     column_split = NULL,
119
-    heatmap_body_width = NULL) {
120
+    width = NULL,
121
+    heatmap_width = NULL) {
120 122
 
121 123
     verbose = ht_opt("verbose")
122 124
 
... ...
@@ -298,6 +300,37 @@ setMethod(f = "make_layout",
298 300
             object@ht_list[[i_main]]@row_order = row_order
299 301
             if(verbose) qqcat("set row_order to main heatmap\n")
300 302
         }
303
+
304
+        
305
+        if(!is.null(height) && !is.null(heatmap_height)) {
306
+            stop_wrap("You can only specify one of `height` and `heatmap_height` in draw().")
307
+        }
308
+        if(!is.null(height)) {
309
+            if(!inherits(height, "unit")) {
310
+                stop_wrap("`height` specified in `draw()` should be a unit.")
311
+            }
312
+            if(!is_abs_unit(height)) {
313
+                stop_wrap("`height` specified in `draw()` should be an absolute unit.")
314
+            }
315
+
316
+        }
317
+        if(!is.null(heatmap_height)) {
318
+            if(!inherits(heatmap_height, "unit")) {
319
+                stop_wrap("`heatmap_height` specified in `draw()` should be a unit.")
320
+            }
321
+            if(!is_abs_unit(heatmap_height)) {
322
+                stop_wrap("`heatmap_height` specified in `draw()` should be an absolute unit.")
323
+            }
324
+        }
325
+        
326
+        if(!is.null(height) && is.null(heatmap_height)) {
327
+            object@ht_list[[i_main]]@matrix_param$height = height
328
+            object@ht_list[[i_main]]@heatmap_param$height = unit(1, "npc")
329
+        } else if(is.null(height) && !is.null(heatmap_height)) {
330
+            object@ht_list[[i_main]]@matrix_param$height = unit(1, "npc")
331
+            object@ht_list[[i_main]]@heatmap_param$height = heatmap_height
332
+        } 
333
+        
301 334
     } else {
302 335
         if(!is.null(column_split)) {
303 336
             object@ht_list[[i_main]]@matrix_param$column_split = column_split
... ...
@@ -386,6 +419,35 @@ setMethod(f = "make_layout",
386 419
             object@ht_list[[i_main]]@column_order = column_order
387 420
             if(verbose) qqcat("set column_order to main heatmap\n")
388 421
         }
422
+
423
+        if(!is.null(width) && !is.null(heatmap_width)) {
424
+            stop_wrap("You can only specify one of `width` and `heatmap_width` in draw().")
425
+        }
426
+        if(!is.null(width)) {
427
+            if(!inherits(width, "unit")) {
428
+                stop_wrap("`width` specified in `draw()` should be a unit.")
429
+            }
430
+            if(!is_abs_unit(width)) {
431
+                stop_wrap("`width` specified in `draw()` should be an absolute unit.")
432
+            }
433
+
434
+        }
435
+        if(!is.null(heatmap_width)) {
436
+            if(!inherits(heatmap_width, "unit")) {
437
+                stop_wrap("`heatmap_width` specified in `draw()` should be a unit.")
438
+            }
439
+            if(!is_abs_unit(heatmap_width)) {
440
+                stop_wrap("`heatmap_width` specified in `draw()` should be an absolute unit.")
441
+            }
442
+        }
443
+        
444
+        if(!is.null(width) && is.null(heatmap_width)) {
445
+            object@ht_list[[i_main]]@matrix_param$width = width
446
+            object@ht_list[[i_main]]@heatmap_param$width = unit(1, "npc")
447
+        } else if(is.null(width) && !is.null(heatmap_width)) {
448
+            object@ht_list[[i_main]]@matrix_param$width = unit(1, "npc")
449
+            object@ht_list[[i_main]]@heatmap_param$width = heatmap_width
450
+        }  
389 451
     }
390 452
 
391 453
     if(verbose) qqcat("auto adjust all heatmap/annotations by the main heatmap\n")
... ...
@@ -486,6 +548,25 @@ setMethod(f = "make_layout",
486 548
         if(verbose) qqcat("adjust column order for all other heatmaps\n")
487 549
     }
488 550
 
551
+    # width and height
552
+    if(direction == "horizontal") {
553
+        for(i in seq_len(n_ht)) {
554
+            if(inherits(object@ht_list[[i]], "Heatmap") & i != i_main) {
555
+                object@ht_list[[i]]@matrix_param$height = object@ht_list[[i_main]]@matrix_param$height
556
+                object@ht_list[[i]]@heatmap_param$height = object@ht_list[[i_main]]@heatmap_param$height
557
+            }
558
+        }
559
+        if(verbose) qqcat("adjust heights for all other heatmaps\n")
560
+    } else {
561
+        for(i in seq_len(n_ht)) {
562
+            if(inherits(object@ht_list[[i]], "Heatmap") & i != i_main) {
563
+                object@ht_list[[i]]@matrix_param$width = object@ht_list[[i_main]]@matrix_param$width
564
+                object@ht_list[[i]]@heatmap_param$width = object@ht_list[[i_main]]@heatmap_param$width
565
+            }
566
+        }
567
+        if(verbose) qqcat("adjust width for all other heatmaps\n")
568
+    }
569
+
489 570
     if(auto_adjust) {
490 571
         if(direction == "horizontal") {
491 572
             for(i in seq_len(n_ht)) {
... ...
@@ -969,18 +1050,48 @@ setMethod(f = "component_width",
969 1050
     } else {
970 1051
         component_name = k
971 1052
     }
1053
+
1054
+    direction = object@direction
972 1055
     # this function is used for grid.layout, so null unit is allowed
973
-    .single_unit = function(nm) {
1056
+    .single_unit_horizontal = function(nm) {
974 1057
         if(nm == "heatmap_list") {
975 1058
              width = sum(do.call("unit.c", lapply(object@ht_list, function(ht) {
976 1059
                     if(inherits(ht, "Heatmap")) {
977 1060
                         ht@heatmap_param$width
978 1061
                     } else {
979
-                        size(ht)
1062
+                        width(ht) # width of the row annotation, always a fixed unit
980 1063
                     }
981 1064
                 })))
982 1065
             if(is_abs_unit(width)) {
983
-                width + sum(object@ht_list_param$ht_gap)
1066
+                width + sum(object@ht_list_param$ht_gap) - object@ht_list_param$ht_gap[length(object@ht_list_param$ht_gap)]
1067
+            } else {
1068
+                unit(1, "null") 
1069
+            }
1070
+        } else {
1071
+            object@layout[[paste0("layout_", nm, "_width")]]
1072
+        }
1073
+    }
1074
+
1075
+    .single_unit_vertical = function(nm) {
1076
+        if(nm == "heatmap_list") {
1077
+            width = max(do.call("unit.c", lapply(object@ht_list, function(ht) {
1078
+                    if(inherits(ht, "Heatmap")) {
1079
+                        ht@heatmap_param$width
1080
+                    } else {
1081
+                        # the width of column annotation is always unit(1, "npc")
1082
+                        w = width(ht)
1083
+                        # if a relative unit, reset to unit(0, "mm")
1084
+                        if(!is_abs_unit(w)) w = unit(0, "mm")
1085
+                        w
1086
+                    }
1087
+                })))
1088
+            if(is_abs_unit(width)) {
1089
+                # if height is zeor, this means, there is no heatmap and no width is set for all heatmapannotations
1090
+                if(convertWidth(width, "mm", valueOnly = TRUE) == 0) {
1091
+                    unit(1, "null")
1092
+                } else {
1093
+                    width
1094
+                }
984 1095
             } else {
985 1096
                 unit(1, "null") 
986 1097
             }
... ...
@@ -989,7 +1100,11 @@ setMethod(f = "component_width",
989 1100
         }
990 1101
     }
991 1102
     
992
-    do.call("unit.c", lapply(component_name, .single_unit))
1103
+    if(direction == "horizontal") {
1104
+        do.call("unit.c", lapply(component_name, .single_unit_horizontal))
1105
+    } else {
1106
+        do.call("unit.c", lapply(component_name, .single_unit_vertical))
1107
+    }
993 1108
 })
994 1109
 
995 1110
 # == title
... ...
@@ -1014,18 +1129,19 @@ setMethod(f = "component_height",
1014 1129
     } else {
1015 1130
         component_name = k
1016 1131
     }
1132
+    direction = object@direction
1017 1133
     # this function is used for grid.layout, so null unit is allowed
1018
-    .single_unit = function(nm) {
1134
+    .single_unit_vertical = function(nm) {
1019 1135
         if(nm == "heatmap_list") {
1020
-            height = max(do.call("unit.c", lapply(object@ht_list, function(ht) {
1136
+             height = sum(do.call("unit.c", lapply(object@ht_list, function(ht) {
1021 1137
                     if(inherits(ht, "Heatmap")) {
1022 1138
                         ht@heatmap_param$height
1023 1139
                     } else {
1024
-                        size(ht)
1140
+                        height(ht) # width of the row annotation, always a fixed unit
1025 1141
                     }
1026 1142
                 })))
1027 1143
             if(is_abs_unit(height)) {
1028
-                height
1144
+                height + sum(object@ht_list_param$ht_gap) - object@ht_list_param$ht_gap[length(object@ht_list_param$ht_gap)]
1029 1145
             } else {
1030 1146
                 unit(1, "null") 
1031 1147
             }
... ...
@@ -1034,5 +1150,35 @@ setMethod(f = "component_height",
1034 1150
         }
1035 1151
     }
1036 1152
 
1037
-    do.call("unit.c", lapply(component_name, .single_unit))
1153
+    .single_unit_horizontal = function(nm) {
1154
+        if(nm == "heatmap_list") {
1155
+            height = max(do.call("unit.c", lapply(object@ht_list, function(ht) {
1156
+                    if(inherits(ht, "Heatmap")) {
1157
+                        ht@heatmap_param$height
1158
+                    } else {
1159
+                        h = height(ht)
1160
+                        if(!is_abs_unit(h)) h = unit(0, "mm")
1161
+                        h
1162
+                    }
1163
+                })))
1164
+            if(is_abs_unit(height)) {
1165
+                # if height is zeor, this means, there is no heatmap and no width is set for all heatmapannotations
1166
+                if(convertWidth(height, "mm", valueOnly = TRUE) == 0) {
1167
+                    unit(1, "null")
1168
+                } else {
1169
+                    height
1170
+                }
1171
+            } else {
1172
+                unit(1, "null") 
1173
+            }
1174
+        } else {
1175
+            object@layout[[paste0("layout_", nm, "_height")]]
1176
+        }
1177
+    }
1178
+    
1179
+    if(direction == "horizontal") {
1180
+        do.call("unit.c", lapply(component_name, .single_unit_horizontal))
1181
+    } else {
1182
+        do.call("unit.c", lapply(component_name, .single_unit_vertical))
1183
+    }
1038 1184
 })
... ...
@@ -111,7 +111,7 @@ ht_opt = setGlobalOptions(
111 111
 			}
112 112
 		},
113 113
 		.length = 1),
114
-	show_vp_border = FALSE,
114
+	show_vp = FALSE,
115 115
 	anno_simple_size = list(
116 116
 		.value = unit(5, "mm"),
117 117
 		.class = "unit"
118 118
new file mode 100644
... ...
@@ -0,0 +1,21 @@
1
+
2
+
3
+# stacked_simple = function(..., name, which = c("row", "column")) {
4
+# 	which = match.arg(which)
5
+# 	arg_list = list()
6
+# 	arg_list$which = which
7
+# 	arg_list[[name]] = anno_simple(..., which = which)
8
+# 	do.call("HeatmapAnnotation", arg_list)
9
+# }
10
+# stacked_points
11
+# stacked_lines
12
+# stacked_image
13
+# stacked_text
14
+# stacked_barplot
15
+# stacked_boxplot
16
+# stacked_histogram
17
+# stacked_joyplot
18
+# stacked_horizon
19
+
20
+
21
+# draw
0 22
\ No newline at end of file
... ...
@@ -73,7 +73,13 @@ default_col = function(x, main_matrix = FALSE) {
73 73
     } else if(is.numeric(x)) {
74 74
         if(main_matrix) {
75 75
             if(length(unique(x)) > 100) {
76
-                col_fun = colorRamp2(seq(quantile(x, 0.01), quantile(x, 0.99), length = 3), c("blue", "#EEEEEE", "red"))
76
+                q1 = quantile(x, 0.01)
77
+                q2 = quantile(x, 0.99)
78
+                if(length(unique(x[x > q1 & x < q2])) == 1) {
79
+                     col_fun = colorRamp2(seq(min(x), max(x), length = 3), c("blue", "#EEEEEE", "red"))
80
+                } else {
81
+                    col_fun = colorRamp2(seq(q1, q2, length = 3), c("blue", "#EEEEEE", "red"))
82
+                }
77 83
             } else {
78 84
                 col_fun = colorRamp2(seq(min(x), max(x), length = 3), c("blue", "#EEEEEE", "red"))
79 85
             }
... ...
@@ -404,7 +410,7 @@ add_vp_name = function(vpname) {
404 410
 }
405 411
 
406 412
 upViewport = function(...) {
407
-    if(ht_global_opt$show_vp_border) {
413
+    if(ht_global_opt$show_vp) {
408 414
         grid.rect(gp = gpar(fill = "transparent", col = "black", lty = 3))
409 415
         vpname = current.viewport()$name
410 416
         if(!grepl("^GRID.VP", vpname)) {
... ...
@@ -415,7 +421,7 @@ upViewport = function(...) {
415 421
 }
416 422
 
417 423
 popViewport = function(...) {
418
-    if(ht_global_opt$show_vp_border) {
424
+    if(ht_global_opt$show_vp) {
419 425
         grid.rect(gp = gpar(fill = "transparent", col = "black", lty = 3))
420 426
         vpname = current.viewport()$name
421 427
         if(!grepl("^GRID.VP", vpname)) {
... ...
@@ -5,7 +5,7 @@
5 5
 ", pkgname, " version ", version, "
6 6
 Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
7 7
 Github page: https://github.com/jokergoo/ComplexHeatmap
8
-Documentation: http://bioconductor.org/packages/ComplexHeatmap/
8
+Documentation: http://jokergoo.github.io/ComplexHeatmap_book
9 9
 
10 10
 If you use it in published research, please cite:
11 11
 Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional 
... ...
@@ -71,3 +71,16 @@ rowAnnotation(foo = 1:10, bar = anno_points(10:1))
71 71
 HeatmapAnnotation(1:10)
72 72
 
73 73
 HeatmapAnnotation(data.frame(1:10))
74
+
75
+
76
+
77
+ha = HeatmapAnnotation(summary = anno_summary(height = unit(4, "cm")))
78
+v = sample(letters[1:2], 50, replace = TRUE)
79
+split = sample(letters[1:2], 50, replace = TRUE)
80
+
81
+Heatmap(v, top_annotation = ha, width = unit(1, "cm"), split = split)
82
+
83
+ha = HeatmapAnnotation(summary = anno_summary(gp = gpar(fill = 2:3), height = unit(4, "cm")))
84
+v = rnorm(50)
85
+Heatmap(v, top_annotation = ha, width = unit(1, "cm"), split = split)
86
+