From 3398d2157df844f4acd5202148dd87a54ca7cb62 Mon Sep 17 00:00:00 2001 From: Zuguang Gu Date: Thu, 19 Dec 2024 13:52:56 +0100 Subject: [PATCH] anno_barplot(): add_numbers and reversed direction --- DESCRIPTION | 4 ++-- NEWS | 7 +++++++ R/AnnotationFunction-function.R | 22 +++++++++++++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c75f457..d1911d3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: ComplexHeatmap Type: Package Title: Make Complex Heatmaps -Version: 2.21.1 -Date: 2024-09-24 +Version: 2.21.2 +Date: 2024-12-19 Authors@R: person("Zuguang", "Gu", email = "z.gu@dkfz.de", role = c("aut", "cre"), comment = c('ORCID'="0000-0002-7395-8709")) Depends: R (>= 3.5.0), methods, grid, graphics, stats, grDevices diff --git a/NEWS b/NEWS index dfe7e95..3d83832 100755 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +CHANGES in VERSION 2.21.2 + +* `anno_barplot()`: fixed a bug when `add_numbers = TRUE` and `axis_param=c(direction="reverse")` are both set. + +======================= + + CHANGES in VERSION 2.21.1 * `pheatmap()`: `na_col` is passed to `Heatmap()`. diff --git a/R/AnnotationFunction-function.R b/R/AnnotationFunction-function.R index 129b0f5..df92a71 100644 --- a/R/AnnotationFunction-function.R +++ b/R/AnnotationFunction-function.R @@ -1371,6 +1371,8 @@ anno_barplot = function(x, baseline = 0, which = c("column", "row"), border = TR value_origin = value value = data_scale[2] - value + data_scale[1] baseline = data_scale[2] - baseline + data_scale[1] + } else { + value_origin = value } pushViewport(viewport(xscale = data_scale, yscale = c(0.5, n+0.5))) @@ -1380,7 +1382,7 @@ anno_barplot = function(x, baseline = 0, which = c("column", "row"), border = TR 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, index)) if(add_numbers) { if(axis_param$direction == "normal") { - txt = value[index] + txt = value_origin[index] if(!is.null(attr(value, "labels_format"))) { txt = attr(value, "labels_format")(value[index]) } @@ -1449,6 +1451,8 @@ anno_barplot = function(x, baseline = 0, which = c("column", "row"), border = TR value_origin = value value = data_scale[2] - value + data_scale[1] baseline = data_scale[2] - baseline + data_scale[1] + } else { + value_origin = value } pushViewport(viewport(yscale = data_scale, xscale = c(0.5, n+0.5))) @@ -1457,15 +1461,23 @@ anno_barplot = function(x, baseline = 0, which = c("column", "row"), border = TR y_coor = height/2+baseline grid.rect(y = y_coor, x = seq_along(index), height = abs(height), width = 1*bar_width, default.units = "native", gp = subset_gp(gp, index)) if(add_numbers) { - txt = value[index] + txt = value_origin[index] if(!is.null(attr(value, "labels_format"))) { txt = attr(value, "labels_format")(value[index]) } numbers_rot = numbers_rot %% 360 - if(numbers_rot == 0) { - grid.text(txt, x = seq_along(index), y = unit(baseline + height, "native") + numbers_offset, default.units = "native", gp = subset_gp(numbers_gp, index), just = c("bottom")) + if(axis_param$direction == "normal") { + if(numbers_rot == 0) { + grid.text(txt, x = seq_along(index), y = unit(baseline + height, "native") + numbers_offset, default.units = "native", gp = subset_gp(numbers_gp, index), just = c("bottom")) + } else { + grid.text(txt, x = seq_along(index), y = unit(baseline + height, "native") + numbers_offset, default.units = "native", gp = subset_gp(numbers_gp, index), just = c("left"), rot = numbers_rot) + } } else { - grid.text(txt, x = seq_along(index), y = unit(baseline + height, "native") + numbers_offset, default.units = "native", gp = subset_gp(numbers_gp, index), just = c("left"), rot = numbers_rot) + if(numbers_rot == 0) { + grid.text(txt, x = seq_along(index), y = unit(baseline + height, "native") - numbers_offset, default.units = "native", gp = subset_gp(numbers_gp, index), just = c("top")) + } else { + grid.text(txt, x = seq_along(index), y = unit(baseline + height, "native") - numbers_offset, default.units = "native", gp = subset_gp(numbers_gp, index), just = c("right"), rot = numbers_rot) + } } } } else {