user2300940
user2300940

Reputation: 2395

turn off repel in legend of complexheatmap

I would like to be able to turn off the black lines that are linked to the numbers in the legend. If I increase the width, they will disappear, but I would like to keep the width as it is.

Is it possible to just add FALSE somewhere?

Minn=-15
Maxx=1
col_fun = colorRamp2(c(Minn,-3.3,Maxx), 
                     c("blue", "#EEEEEE", "red"))

lgd_sig2 = Legend(col_fun=col_fun,
                  title = "Abundance (log2)",
                  legend_height = unit(1.5, "cm"),
                  title_position = "topcenter",
                  title_gp = gpar(fontsize = 5),
                  labels_gp = gpar(fontsize = 5),
                  direction = "horizontal",
                  at = c(Minn,-3.3,Maxx),
                  labels_rot = 0,
                  grid_height = unit(0.25, "cm"),
                  legend_width = unit(1.22, "cm"))

enter image description here

Upvotes: 1

Views: 369

Answers (1)

jared_mamrot
jared_mamrot

Reputation: 26225

One potential option is to set the break_dist parameter to space out the values more evenly. E.g. in the bottom legend break_dist = 1:

library(ComplexHeatmap)
library(circlize)

set.seed(123)
nr1 = 4; nr2 = 8; nr3 = 6; nr = nr1 + nr2 + nr3
nc1 = 6; nc2 = 8; nc3 = 10; nc = nc1 + nc2 + nc3
mat = cbind(rbind(matrix(rnorm(nr1*nc1, mean = 1,   sd = 0.5), nr = nr1),
                  matrix(rnorm(nr2*nc1, mean = 0,   sd = 0.5), nr = nr2),
                  matrix(rnorm(nr3*nc1, mean = 0,   sd = 0.5), nr = nr3)),
            rbind(matrix(rnorm(nr1*nc2, mean = 0,   sd = 0.5), nr = nr1),
                  matrix(rnorm(nr2*nc2, mean = 1,   sd = 0.5), nr = nr2),
                  matrix(rnorm(nr3*nc2, mean = 0,   sd = 0.5), nr = nr3)),
            rbind(matrix(rnorm(nr1*nc3, mean = 0.5, sd = 0.5), nr = nr1),
                  matrix(rnorm(nr2*nc3, mean = 0.5, sd = 0.5), nr = nr2),
                  matrix(rnorm(nr3*nc3, mean = 1,   sd = 0.5), nr = nr3))
)
mat = mat[sample(nr, nr), sample(nc, nc)] # random shuffle rows and columns
rownames(mat) = paste0("row", seq_len(nr))
colnames(mat) = paste0("column", seq_len(nc))

col_fun = colorRamp2(c(0, 0.5, 1), c("blue", "white", "red"))

Heatmap(mat)
lgd = Legend(col_fun = col_fun, title = "matrix",
             at = c(0, 0.1, 0.15, 0.5, 0.9, 0.95, 1))
draw(lgd, x = unit(0.985, "npc"), y = unit(0.96, "npc"), just = c("right", "top"))

lgd2 = Legend(col_fun = col_fun, title = "matrix",
              at = c(0, 0.1, 0.15, 0.5, 0.9, 0.95, 1), break_dist = 1)
draw(lgd2, x = unit(0.975, "npc"), y = unit(0.35, "npc"), just = c("right", "top"))

Created on 2022-10-25 by the reprex package (v2.0.1)

Upvotes: 0

Related Questions