...
|
...
|
@@ -199,14 +199,11 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
|
199
|
199
|
}
|
200
|
200
|
}
|
201
|
201
|
|
202
|
|
- if(which == "column") {
|
203
|
|
- anno_list = rev(anno_list)
|
204
|
|
- }
|
205
|
|
-
|
206
|
202
|
n_anno = length(anno_list)
|
207
|
203
|
|
208
|
204
|
if(is.null(gap)) gap = unit(0, "mm")
|
209
|
205
|
|
|
206
|
+ # the nth gap does not really matter
|
210
|
207
|
if(length(gap) == 1) {
|
211
|
208
|
.Object@gap = rep(gap, n_anno)
|
212
|
209
|
} else if(length(gap) == n_anno - 1) {
|
...
|
...
|
@@ -214,6 +211,7 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
|
214
|
211
|
} else if(length(gap) < n_anno - 1) {
|
215
|
212
|
stop("Length of `gap` is wrong.")
|
216
|
213
|
} else {
|
|
214
|
+ gap[n_anno] = unit(0, "mm")
|
217
|
215
|
.Object@gap = gap
|
218
|
216
|
}
|
219
|
217
|
|
...
|
...
|
@@ -231,8 +229,6 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
|
231
|
229
|
anno_size = anno_size/sum(anno_size)*(unit(1, "npc") - sum(.Object@gap))
|
232
|
230
|
}
|
233
|
231
|
|
234
|
|
- if(which == "column") anno_size = anno_size[rev(seq_len(n_anno))]
|
235
|
|
-
|
236
|
232
|
names(anno_list) = sapply(anno_list, function(x) x@name)
|
237
|
233
|
.Object@anno_list = anno_list
|
238
|
234
|
.Object@anno_size = anno_size
|
...
|
...
|
@@ -391,18 +387,30 @@ setMethod(f = "draw",
|
391
|
387
|
gap = object@gap
|
392
|
388
|
|
393
|
389
|
pushViewport(viewport(...))
|
394
|
|
- for(i in seq_len(n_anno)) {
|
395
|
|
- if(which == "column") {
|
396
|
|
- if(align_to == "bottom") {
|
397
|
|
- pushViewport(viewport(y = sum(anno_size[seq_len(i)]) + sum(gap[seq_len(i)]) - gap[i], height = anno_size[i], just = c("center", "top")))
|
398
|
|
- } else {
|
399
|
|
- pushViewport(viewport(y = unit(1, "npc") - (sum(anno_size[seq(i, n_anno)]) + sum(gap[seq(i, n_anno)]) - gap[n_anno + 1 - i]), height = anno_size[i], just = c("center", "bottom")))
|
|
390
|
+ if(which == "column") {
|
|
391
|
+ if(align_to == "bottom") { # put on top of the heatmap
|
|
392
|
+ # start from the last annoation which is put on bottom
|
|
393
|
+ for(i in rev(seq_len(n_anno))) {
|
|
394
|
+ pushViewport(viewport(y = sum(anno_size[seq(n_anno - i + 1, n_anno))]) + sum(gap[seq(n_anno - i + 1, n_anno)]) + gap[n_anno],
|
|
395
|
+ height = anno_size[i], just = c("center", "top"))
|
|
396
|
+ draw(object@anno_list[[i]], index, k, n)
|
|
397
|
+ upViewport()
|
400
|
398
|
}
|
401
|
|
- } else {
|
|
399
|
+ } else { # put on bottom of the heatmap
|
|
400
|
+ # start for the first annotation which is put on the top
|
|
401
|
+ for(i in seq_len(n_anno)) {
|
|
402
|
+ pushViewport(viewport(y = unit(1, "npc") - (sum(anno_size[seq_len(i)]) + sum(gap[seq_len(i)]) - gap[i]),
|
|
403
|
+ height = anno_size[i], just = c("center", "bottom"))
|
|
404
|
+ draw(object@anno_list[[i]], index, k, n)
|
|
405
|
+ upViewport()
|
|
406
|
+ }
|
|
407
|
+ }
|
|
408
|
+ } else if(which == "row") {
|
|
409
|
+ for(i in seq_len(n_anno)) {
|
402
|
410
|
pushViewport(viewport(x = sum(anno_size[seq_len(i)]) + sum(gap[seq_len(i)]) - gap[i], width = anno_size[i], just = c("right", "center")))
|
|
411
|
+ draw(object@anno_list[[i]], index, k, n)
|
|
412
|
+ upViewport()
|
403
|
413
|
}
|
404
|
|
- draw(object@anno_list[[i]], index, k, n)
|
405
|
|
- upViewport()
|
406
|
414
|
}
|
407
|
415
|
upViewport()
|
408
|
416
|
})
|