Edit row and col names in Pheatmap

Al14 picture Al14 · Aug 16, 2015 · Viewed 16.5k times · Source

I want to edit row and col names in my pheatmap or eventually delete and add new row and col names to be edited. In this case I will set show_colnames and show_rownames to FALSE.

library("pheatmap")
pheatmap(scale(dat), show_colnames = T, show_rownames = T,legend = TRUE,
             cluster_rows=F, cluster_cols=F, border_color = "grey60")

Can somebody help me thanks.

Answer

zero323 picture zero323 · Aug 16, 2015

You can use labels_row and labels_col parameters.

> set.seed(1)
> mat <- matrix(rnorm(100), 10, 10, dimnames=list(letters[1:10], letters[11:20]))
> pheatmap(mat)

enter image description here

> pheatmap(mat, labels_row=paste0("foo", 1:10), labels_col=paste0("bar", 1:10))

enter image description here

Alternatively you can modify rownames / colnames of the matrix you pass to the pheatmap function.

library(magrittr)

mat %>%
    set_rownames(paste0("foo", 1:10)) %>%
    set_colnames(paste0("bar", 1:10)) %>%
    pheatmap()