Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rmflight/5648380b4df84cb1ef948101151aa261 to your computer and use it in GitHub Desktop.
Save rmflight/5648380b4df84cb1ef948101151aa261 to your computer and use it in GitHub Desktop.
m = matrix(rnorm(100), 10)
rownames(m) = paste0("row", 1:10)
colnames(m) = paste0("column", 1:10)
ht = draw(Heatmap(m, name = "mat"))
highlight_row = function(which, padding = unit(1, "mm"), gp = gpar()) {
row_order = row_order(ht)
i = which(row_order == which)
nr = length(row_order)
decorate_heatmap_body("mat", {
grid.rect(x = 0.5, y = unit((nr-i+0.5)/nr, "npc"),
width = unit(1, "npc") + padding*2,
height = unit(1/nr, "npc") + padding*2,
default.units = "npc",
gp = gp)
})
}
highlight_row(3, gp = gpar(fill = "#00FF0040", col = "black", lty = 2))
highlight_column = function(which, padding = unit(1, "mm"), gp = gpar()) {
column_order = column_order(ht)
i = which(column_order == which)
nc = length(column_order)
decorate_heatmap_body("mat", {
grid.rect(x = unit((i-0.5)/nc, "npc"), y = 0.5,
width = unit(1/nc, "npc") + padding*2,
height = unit(1, "npc") + padding*2,
default.units = "npc",
gp = gp)
})
}
highlight_column(5, padding = unit(3, "mm"), gp = gpar(fill = "#00FFFF40", col = "orange", lwd = 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment