The pheatmap function in R

The pheatmap function in R, the pheatmap function gives you more control over the final plot than the standard base R heatmap does.

A numerical matrix holding the values to be plotted can be passed.

How to create Anatogram plot in R – Data Science Tutorials

# install.packages("pheatmap")
library(pheatmap)
# Data 
set.seed(123)
m <- matrix(rnorm(200), 10, 10)
colnames(m) <- paste("Col", 1:10)
rownames(m) <- paste("Row", 1:10)
# Heat map
pheatmap(m)

Normalization

If the matrix’s values are not normalized, you can use the scale parameter to normalize them by either the rows (“row”) or the columns (“column”) of the matrix.

How to Create an Interaction Plot in R? – Data Science Tutorials

m <- matrix(rnorm(200), 10, 10)
colnames(m) <- paste("Col", 1:10)
rownames(m) <- paste("Row", 1:10)
# Heat map
pheatmap(m, scale = "column")

Values

Display_numbers = TRUE causes the values for each cell to be displayed. The text’s size and colour can both be changed.

pheatmap(m,
         display_numbers = TRUE,
         number_color = "black", 
         fontsize_number = 8)

How to Rank by Group in R? – Data Science Tutorials

Number of clusters

With kmeans_k, the number of clusters can be altered. If there aren’t enough clusters, you can enlarge the cells using cellheight or cellwidth.

pheatmap(m, kmeans_k = 3, cellheight = 50)

Remove rows dendrogram

pheatmap(m, cluster_rows = FALSE)

Remove columns dendrogram

pheatmap(m, cluster_cols = FALSE)

How to create a ggalluvial plot in R? – Data Science Tutorials

Remove dendrograms

pheatmap(m,
         cluster_cols = FALSE,
         cluster_rows = FALSE)

Border color

pheatmap(m, border_color = "black")

Color palette

pheatmap(m, color = hcl.colors(50, "BluYl"))

Legend breaks

heatmap(m, legend_breaks = c(-2, 0, 2))

Legend labels

pheatmap(m,
         legend_breaks = c(-2, 0, 2),
         legend_labels = c("Low", "Medium", "High"))

How to Use Spread Function in R?-tidyr Part1 (datasciencetut.com)

Remove the legend

pheatmap(m, legend = FALSE)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

one + nineteen =