can i change the column names to the top in PHEATMAP

Viewed 1393

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.

2 Answers

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

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

Related