Skip to content

Commit

Permalink
anno_barplot(): add_numbers and reversed direction
Browse files Browse the repository at this point in the history
  • Loading branch information
jokergoo committed Dec 19, 2024
1 parent 0d273cd commit 3398d21
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("aut", "cre"),
comment = c('ORCID'="0000-0002-7395-8709"))
Depends: R (>= 3.5.0), methods, grid, graphics, stats, grDevices
Expand Down
7 changes: 7 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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()`.
Expand Down
22 changes: 17 additions & 5 deletions R/AnnotationFunction-function.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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])
}
Expand Down Expand Up @@ -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)))
Expand All @@ -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 {
Expand Down

0 comments on commit 3398d21

Please sign in to comment.