Replies: 1 comment 2 replies
-
You just put everything is a function and call make_plot = function() {
set.seed(123)
mat2 = matrix(rnorm(50*50), nrow = 50)
ha = HeatmapAnnotation(
empty = anno_empty(border = FALSE),
foo = anno_block(gp = gpar(fill = 2:6), labels = LETTERS[1:5]))
split = rep(1:5, each = 10)
ht_list= Heatmap(mat2, name = "mat2", column_split = split, top_annotation = ha,
column_title = NULL)
draw(ht_list)
seekViewport("annotation_empty_1")
loc1 = deviceLoc(x = unit(0, "npc"), y = unit(0, "npc"))
seekViewport("annotation_empty_3")
loc2 = deviceLoc(x = unit(1, "npc"), y = unit(1, "npc"))
seekViewport("global")
grid.rect(loc1$x, loc1$y, width = loc2$x - loc1$x, height = loc2$y - loc1$y,
just = c("left", "bottom"), gp = gpar(fill = "red"))
grid.text("group 1", x = (loc1$x + loc2$x)*0.5, y = (loc1$y + loc2$y)*0.5)
}
gb = grid.grabExpr(make_plot()) Then you can use |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I made a heatmap with Complexheatmap package I added a few filled rectangles+text with grid.rect and grid.text. I would like to grob this plot or save it as a gtable so I can add it to a panel. However I cant grob it or save it as a gtable object. I can only
library(ComplexHeatmap)
gb_heatmap = grid.grabExpr(draw(ht_list, heatmap_legend_side = "right"))
hm_gtable <- gtable_matrix("hm_gtbl", matrix(list(gb_heatmap)), unit(1, "null"), unit(1, "null"))
when running thise code I the grid.rect and grid.text elements are not saved in the gtable object.
Help would be appreciated.
cheers,
Beta Was this translation helpful? Give feedback.
All reactions