2

I am using PHEATMAP to generate a heatmap - currently the row names and column names defaults to left and bottom - can somebody point me to option where i can change it to RIGHT and TOP.

Tal Galili
  • 24,605
  • 44
  • 129
  • 187
Neo
  • 67
  • 5
  • It might be easier to use a package that exposes that option than to try to achieve this with pheatmap - e.g. using ComplexHeatmap for that (https://jokergoo.github.io/ComplexHeatmap-reference/book/heatmap-annotations.html) – user12728748 Aug 06 '20 at 19:47
  • I agree - i know complex heatmap is so easy in achieving this, the problem is that i am using powerbi to load this Heatmap to read into my powerapp. Currently powerbi doesn't support complex heatmap. – Neo Aug 06 '20 at 19:58

2 Answers2

0

You can reverse the order of rows and columns as follows:

library(pheatmap)
library(gridExtra)
# Heatmap of the original data set
p1 <- pheatmap(mtcars, cluster_cols=F, cluster_rows=F)

# Heatmap of the data set with flipped rows and columns
mtcars2 <- mtcars[nrow(mtcars):1, ncol(mtcars):1]
p2 <- pheatmap(mtcars2, cluster_cols=F, cluster_rows=F)

grid.arrange(grobs=list(p1$gtable,p2$gtable), nrow=1)

enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
  • 1
    Thanks Marco - This would be helpful as well. I am looking at moving the location of the column labels to the top of the chart and row labels to the left of the chart. – Neo Aug 13 '20 at 13:30
  • @Neo did you find a solution for this? I am after the same issue – Ecg Feb 26 '21 at 12:31
0

Unfortunately, you must use ComplexHeatmap - I'm aware OP cannot use CH but posterity for others:

library(pheatmap)
pheatmap(plot_mat, cluster_rows = T, cluster_cols = F,
         display_numbers = T, cutree_rows = 3, 
         color = hcl.colors(50, "sunsetdark", rev=F),
         border_color = "black", number_color = "black",
         fontsize_number = 9, angle_col = 0)

pheatmap

library(ComplexHeatmap)
ComplexHeatmap::pheatmap(plot_mat, cluster_rows = T, cluster_cols = F,
                         display_numbers = T, cutree_rows = 3, 
                         color = hcl.colors(50, "sunsetdark", rev=F), 
                         border_color = "black", number_color = "black",
                         fontsize_number = 9, column_names_side = c("top"),
                         angle_col = c("0"))

complexheatmap

Barry D
  • 43
  • 1
  • 6