Skip to content

Commit

Permalink
anno_density(): fixed a bug in heatmap density
Browse files Browse the repository at this point in the history
  • Loading branch information
jokergoo committed Oct 6, 2022
1 parent 82309c0 commit cdb9fb7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Type: Package
Title: Make Complex Heatmaps
Version: 2.13.2
Date: 2022-08-31
Author: Zuguang Gu
Maintainer: Zuguang Gu <z.gu@dkfz.de>
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
Imports: circlize (>= 0.4.14), GetoptLong, colorspace, clue,
RColorBrewer, GlobalOptions (>= 0.1.0), png,
Expand Down
15 changes: 6 additions & 9 deletions R/AnnotationFunction-function.R
Original file line number Diff line number Diff line change
Expand Up @@ -2112,17 +2112,17 @@ anno_density = function(x, which = c("column", "row"),
width = density_x[[i]][-1] - density_x[[i]][-n_breaks], height = 1,
just = c("right", "bottom"), default.units = "native",
gp = gpar(fill = col_fun((density_y[[i]][-1] + density_y[[i]][-n_breaks])/2),
col = NA))
col = col_fun((density_y[[i]][-1] + density_y[[i]][-n_breaks])/2)))
if(density_x[[i]][1] - min_density_x > 0) {
grid.rect(x = density_x[[i]][1], y = 0, width = density_x[[i]][1] - min_density_x,
height = 1, just = c("right", "bottom"), default.units = "native",
gp = gpar(fill = col_fun(0), col = NA))
gp = gpar(fill = col_fun(0), col = col_fun(0)))
}
if(max_density_x - density_x[[i]][n_breaks] > 0) {
grid.rect(x = density_x[[i]][n_breaks], y = 0,
width = max_density_x - density_x[[i]][n_breaks], height = 1,
just = c("left", "bottom"), default.units = "native",
gp = gpar(fill = col_fun(0), col = NA))
gp = gpar(fill = col_fun(0), col = col_fun(0)))
}
}
popViewport()
Expand All @@ -2149,16 +2149,13 @@ anno_density = function(x, which = c("column", "row"),
density_x = density_x[index]
density_y = density_y[index]

yscale = range(unlist(density_x), na.rm = TRUE)
yscale = yscale + c(0, 0.05)*(yscale[2] - yscale[1])
if(type == "lines") {
xscale = c(0, max(unlist(density_y)))
xscale[2] = xscale[2]*1.05
} else if(type == "violin") {
xscale = max(unlist(density_y))
xscale = c(-xscale*1.05, xscale*1.05)
} else if(type == "heatmap") {
yscale = range(unlist(density_x), na.rm = TRUE)
xscale = c(0, 1)
min_y = min(unlist(density_y))
max_y = max(unlist(density_y))
Expand Down Expand Up @@ -2192,17 +2189,17 @@ anno_density = function(x, which = c("column", "row"),
height = density_x[[i]][-1] - density_x[[i]][-n_breaks], width = 1,
just = c("left", "top"), default.units = "native",
gp = gpar(fill = col_fun((density_y[[i]][-1] + density_y[[i]][-n_breaks])/2),
col = NA))
col = col_fun((density_y[[i]][-1] + density_y[[i]][-n_breaks])/2)))
if(density_x[[i]][1] - min_density_x > 0) {
grid.rect(y = density_x[[i]][1], x = 0, height = density_x[[i]][1] - min_density_x,
width = 1, just = c("left", "top"), default.units = "native",
gp = gpar(fill = col_fun(0), col = NA))
gp = gpar(fill = col_fun(0), col = col_fun(0)))
}
if(max_density_x - density_x[[i]][n_breaks] > 0) {
grid.rect(y = density_x[[i]][n_breaks], x = 0,
height = max_density_x - density_x[[i]][n_breaks], width = 1,
just = c("left", "bottom"), default.units = "native",
gp = gpar(fill = col_fun(0), col = NA))
gp = gpar(fill = col_fun(0), col = col_fun(0)))
}
}
popViewport()
Expand Down

0 comments on commit cdb9fb7

Please sign in to comment.