5

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.

Al14
  • 1,734
  • 6
  • 32
  • 55
  • Have you tried anything? What is the structure of a `pheatmap` object? – MichaelChirico Aug 16 '15 at 21:39
  • 2
    @AI14 : You lucked out and got an immediate response from someone who had a copy of whatever package this function resides in. But next time that you post a question about a function that is not in the "base" set of packages, you really ought to post a `library` or `require` call to load the mystery-package. You should NOT assume that we will know whether or not it is in a package of the same name. – IRTFM Aug 16 '15 at 23:24

1 Answers1

4

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()
zero323
  • 322,348
  • 103
  • 959
  • 935
  • HI I am trying to edit `set_rownames` and `set_colnames` adding `plot(1, xaxt="n", yaxt="n"); axis(1, las=2); axis(2, las=1)` but it does not work. How can I rotate axis labels in a pheatmap? – Al14 Aug 17 '15 at 10:25
  • Hi @zero323 would you know how to only show selected row label names based on their names (ie: foo1, foo6) ? – Ecg Apr 07 '21 at 16:47