This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How do I add row names to pheatmap() when I am using a pre-normalized matrix?

I have extracted normalized values from DESeq2 because I want to display only certain genes. I would now like to create a heatmap with my final matrix. This is the code I am using, but I haven't figured out how to assign the first column of my matrix to "show_rownames."

library(pheatmap)

df = read.csv("Genes.csv")
head (df)

df_num = as.matrix(df[,2:16])
pheatmap(df_num, cluster_rows=TRUE, show_rownames=TRUE, cluster_cols=FALSE)

Here are some of the codes I have tried, (1) rownames(df) = sapply(df$Gene,function(x), (2) rownames(df_num) = ("Gene"), (3) data <- read.delim(df, header=T, row.names="Gene")

Thanks in advance

pheatmap heatmap rna-seq

Please show head(df). Generally, a question is only reproducible when you show code and data examples. In R, if your column with genes was Gene then it would be

rownames(df) <- df$Gene
ï..Gene           Z.1         Z.6        Z.15      Z.24
1 CAGL0M12947g -0.04576711  5.943540  3.24204916  0.03980048
2 CAGL0G00286g  0.16523749 -1.842940 -0.08534494  1.58662284
3 CAGL0K05995g -1.13833029  3.276086  1.59363959  0.90730433
4 CAGL0F08041g -1.87245589 -3.160837  0.28749891 -0.77401525
5 CAGL0D06512g -0.12716282  6.001221  2.55006118  3.62156448
6 CAGL0I01980g  1.93672280  1.051457 -0.88983176 -1.65313931
  Z.48          A.1          A.6         A.15     A.24
1 -4.0406250  0.83585503  0.19142180 -0.3642014 -6.1013301
2  4.1306384 -0.72052353 -0.56270243  1.2256163  3.0500250
3 -1.3880211  0.02849869 -0.31382794 -0.6351936 -3.9294826
4  0.3273032  0.05053740 -1.66548272  1.2734138  0.8195757
5 -3.4672651  0.71927202 -0.06539531 -1.4596001 -4.4770075
6  0.9004427 -0.51563130 -1.27491728 -2.0636184 -1.9940903
   A.48
1 -1.65428052
2  2.67099101
3 -0.93206806
4  0.89712845
5 -1.34004060
6  0.07475464

R took your code with no error but I am still not seeing row names

library(pheatmap)

df = read.csv("Genes.csv")
head (df)

df_num = as.matrix(df[,2:16])
rownames(df) <- df$Gene
pheatmap(df_num, cluster_rows=TRUE, show_rownames=TRUE, cluster_cols=FALSE)

I added this and it worked

Above code +

> rownames(df_num) = sapply(df$ï..gene,function(x) strsplit(as.character(x),split = " "))
> pheatmap(df_num, cluster_rows=TRUE, show_rownames=TRUE, cluster_cols=FALSE)

Just an FYI, your code is doing the same thing as the code above. Your column is named ï..Gene and not just Gene which isn't super clear in your previous post. The strsplit part of your sapply is doing nothing because you don't have any spaces in your ï..Gene column.

0 answers

No answers yet.

Log in to answer this question.