Part13 Heatmaps with {pheatmap}

We will introduce package {pheatmap} to produce heatmaps.

First we can install pheatmap (bottom-right panel -> Packages -> Install).

And then we load the package: tick the package in the list, or load it from the console:


library(pheatmap)

pheatmap is not from the tidyverse package, and does not follow the same structure. It does not work with layers, but with multiple parameters inside a same function.

Let’s read the following data file, and convert it to matrix (that is the input format for pheatmap):

expr_heatmap <- read_csv("DataViz_source_files-main/files/GSE150029_rnaseq_for_heatmap.csv") %>%
  column_to_rownames(var = "gene_name") %>%
  as.matrix()

You can then simply plot the heatmap, giving the matrix as an input:

pheatmap(expr_heatmap)

Control what is clusters: rows, columns, both, or none:

pheatmap(expr_heatmap, cluster_cols=FALSE, cluster_rows=TRUE)

Show or hide row names:

pheatmap(expr_heatmap, show_rownames = F)

Change the color scale (rainbow() and heat.colors() are available from the base packages):

pheatmap(expr_heatmap, color = rainbow(10))

pheatmap(expr_heatmap, color = heat.colors(10))