Entering edit mode
I have made a very, very large heatmap. I am almost done, I love the way it looks. However, I am never managing to put the legend (separate object) where I want.
I made the legend like this :
lgd = Legend(title = "Log 2 fold-change", col_fun = colorRamp2(c(-3, 0, +3), c("#00aba9", "white", "#ff0097")),at = seq(-4,+4,by=2))
lgd2=Legend(title="Gene type",labels = c("protein-coding", "non-coding RNA", "pseudo gene"),legend_gp = gpar(fill =c("#673888","#c0c5ce","#eae374")))
pd=packLegend(lgd,lgd2,direction="horizontal")
Then the heatmap :
ha = HeatmapAnnotation(foo = anno_block(gp = gpar(fill = c("#f7a583","#00ff83")),labels = c("F6", "F0"), labels_gp = gpar(col = "black", fontsize = 25)),show_legend=FALSE)
ha2 = HeatmapAnnotation(df = annot_row, which="row",show_annotation_name = FALSE,show_legend=FALSE, annotation_legend_param=list(title= "gene type"),col=col_types,width = unit(7, "cm"))
tryout<-Heatmap(cent_expr_matrix, name = "Log2FC", km = 5, col = colorRamp2(c(-3, 0, +3), c("#00aba9", "white", "#ff0097")),
top_annotation = ha, column_split=annot_col$generation, right_annotation=ha2,show_row_names = TRUE, show_column_names=TRUE,show_column_dend=FALSE,show_row_dend=TRUE,
row_dend_width = unit(50, "mm"), column_title=NULL, width = unit(0.8, "snpc"), clustering_distance_rows = "pearson", show_heatmap_legend = FALSE)
# save the very long heatmap :
cairo_pdf("/home/heatmap_try.pdf",width = 40, height = 345,onefile = FALSE)
draw(tryout, heatmap_legend_list = pd,heatmap_legend_side = "left")
dev.off()
Which puts the legend on the left, at half the height of the heatmap :
I would like to be able to make it bigger, and at the top left side of the heatmap. But I am not finding how to do.

Thank you I just did ! I think I am managing to make a bigger legend, but it is not changing its position though.
There is a 'just' argument for
drawthat has as its default 'center'. Getting to the corresponding help page is not intuitive though. If you do?draw, the help page will tell you that there is anS4method forLegendsobjects which indirectly points to thedraw,Legends-methodhelp. But getting to that help page can be a pain. For example, on Windows using Emacs/ESS,?'draw,Legends-method'just hangs, and I have to usehelp("draw,Legends-method", package = "ComplexHeatmap")instead. Maybe it's different on RStudio, but I am an old dog and refuse to learn that new trick. Anyway,I realize now how naive my question was. It is pretty much only a matter of adjusting x and y. The combinations of x and y in the draw call and in pushViewport where putting my legend far outside of the plot window. Thank you again !