I want to add a line though 0 in a bar chart annotation in a splitted heatmap. The only way I managed so far is to add a line with decorate_annotation.
But unfortunately this does not plot over the annotations of all the heatmap clusters, but just the top cluster:
Here is my how I approached this:
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))
category <- rep(c("A","B","C"), each = 6)
Heatmap(mat,
right_annotation = rowAnnotation(bar2 = anno_barplot(rnorm(18, mean = 0, sd = 2),
gp = gpar(col = "white", fill = "black"))),
show_row_dend = FALSE,
show_column_dend = FALSE,
split = category
)
decorate_annotation("bar2", {
grid.lines(c(0, 0), c(0.5, 17.5), gp = gpar(col = "red"),
default.units = "native")
})
Hello,
I want to add a line though 0 in a bar chart annotation in a splitted heatmap. The only way I managed so far is to add a line with decorate_annotation.
But unfortunately this does not plot over the annotations of all the heatmap clusters, but just the top cluster:
Here is my how I approached this:
Do you have any advice? Thank you so much!
Best, Marlene