0

I have this code which produces this image, how do I change the grid.text so that the range legends show at the bottom, and that I can alter the size and also position of where they are, for example one under the other?

ht1<-Heatmap(merged2, 
        show_row_dend = FALSE,
        show_column_dend = FALSE,
        show_row_names = FALSE,
                 row_names_gp = gpar(fontsize = 8),
         column_names_gp = gpar(fontsize = 8),

            name = "# Var4 long name,# Var5 long name,# Var6 long name,# Var7 long name", cell_fun = function(j, i, x, y, width, height, fill) 
        {
          grid.text(sprintf("%.0f", merged2[i, j]), x, y, gp = gpar(fontsize = 8))
        }
        ,
        col = colorRamp2(c(-max_merged, 0, max_merged), c(rgb(200/255, 202/255, 201/255), rgb(240/255, 240/255, 240/255), rgb(116/255, 122/255, 119/255))))

ht2<-Heatmap(mergedvc2, 
        show_row_dend = FALSE,
        show_column_dend = FALSE,
        #show_row_names = FALSE,
         # list(axis.text.x = element_text(size = 10,face = "bold")),
        row_names_side = "left",
         row_names_gp = gpar(fontsize = 8),
         column_names_gp = gpar(fontsize = 8),


        #heatmap_legend_side = "bottom",

            name = "# Var2", cell_fun = function(j, i, x, y, width, height, fill) 
        {
          grid.text(sprintf("%.0f", mergedvc2[i, j]), x, y, gp = gpar(fontsize = 8))
        },
        col = colorRamp2(c(0, max_mergedvc), c(rgb(72/255, 130/255, 58/255),rgb(203/255, 229/255, 197/255)))
        )


ht_list<-ht2+ht4

draw(ht_list, gap = unit(0, "cm"))
Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
Evan
  • 59
  • 2
  • 7
  • The code doesn't quite match the plot, the plot is 4 heatmaps but the post wouldn't let me post with so much code so provided partial for reference, hope it makes sense what I am trying to achieve? – Evan Sep 10 '18 at 14:30
  • Welcome to Stackoverflow. The reason why SO stopped you from publishing your question is because you do not explain much here. Please edit your question to clarify your problem description. Add some context. Describe your code etc. For guidance please check the [how to ask](https://stackoverflow.com/help/how-to-ask) page and [how to create a minimal example](https://stackoverflow.com/help/mcve) page – 5th Sep 10 '18 at 14:35
  • The question asks everything - I have this code which produces this image, how do I change the grid.text so that the range legends show at the bottom, and that I can alter the size and also position of where they are, for example one under the other? I just would like advice on how to move and resize the legends at the right of the heatmap. It is 4 heatmaps joined together and this piece of code creates them - name = "# Var2", cell_fun = function(j, i, x, y, width, height, fill) { grid.text(sprintf("%.0f", mergedvc2[i, j]), x, y, gp = gpar(fontsize = 8)) } – Evan Sep 12 '18 at 13:03
  • Read the resources I linked and edit the question accordingly please! Otherwise there will probably no answers – 5th Sep 12 '18 at 13:06
  • I apologise you seem to be irritated with me, I have read the links, I am not sure how to change this, the image you can see has legends at the right side of the plot, I would like to know how to make them smaller and reposition them. The post title says this and the question under the post title says this. I completely understand you are clearly telling me my post is not well enough written and I am likely to not receive any responses, thankyou for letting me know. – Evan Sep 12 '18 at 13:51
  • 1
    tbh, your question is not bad. The problem is that nobody can **reproduce your problem** because you do not add your data. Which is fine. If there is too much data then you should not add it. Usually you generate data and try replicating your problem. Concerning how you can change your post - This here explains it quite well: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – 5th Sep 12 '18 at 14:17
  • yeah I did think to add some data, guess I was hoping it would just be a key like heatmap_legend_size or something, I did figure out how to adjust the size by adding this - ht_global_opt(heatmap_legend_title_gp = gpar(fontsize = 5, fontface = "bold"), heatmap_legend_labels_gp = gpar(fontsize = 5), heatmap_column_names_gp = gpar(fontsize = 5)), just need to figure out to to move them now, but I am getting there. If I don't make progress I will add some data. – Evan Sep 12 '18 at 14:32

0 Answers0