jokergoo / ComplexHeatmap

Make Complex Heatmaps
https://jokergoo.github.io/ComplexHeatmap-reference/book/
Other
1.29k stars 225 forks source link

anno_link() align_to wrong shifted #921

Open mligerhe opened 2 years ago

mligerhe commented 2 years ago

Using the R version 4.1.3 (2022-03-10) and the Complex Heatmap 2.10.0, following the example from https://jokergoo.github.io/ComplexHeatmap-reference/book/heatmap-annotations.html#zoom-annotation

set.seed(123)
m = matrix(rnorm(100*10), nrow = 100)
subgroup = sample(letters[1:3], 100, replace = TRUE, prob = c(1, 5, 10))
rg = range(m)
panel_fun = function(index, nm) {
    pushViewport(viewport(xscale = rg, yscale = c(0, 2)))
    grid.rect()
    grid.xaxis(gp = gpar(fontsize = 8))
    grid.boxplot(m[index, ], pos = 1, direction = "horizontal")
    popViewport()
}
anno = anno_link(align_to = subgroup, which = "row", panel_fun = panel_fun, 
    size = unit(2, "cm"), gap = unit(1, "cm"), width = unit(4, "cm"))
Heatmap(m, name = "mat", right_annotation = rowAnnotation(foo = anno), row_split = subgroup)

it should plot the following heatmap: image

However, I obtained shifted boxes for the annotation boxplot. See following image remaked in red where the boxes are shifted: examplenotworking

mligerhe commented 2 years ago

FYI. I found out that when you save it in .svg, it automatically aligns correctly.

jokergoo commented 2 years ago

Did you see any information from the terminal? Or did you manually change the graphical window size, e.g. by dragging it?