0

I am drawing a heat map of some gene expression in Rstudio, but the row names (which should be samples or gene names) are replaced by numbers. I have checked some posts but no chance. sorry if it is a simple question or duplicate, I am new in R.

Here is my R script:

###############################################################

library(heatmaply)

filename <- "TFzebra-TMM-name.matrix"

head(filename)

my_data <- read.table(filename, sep='\t', quote='', stringsAsFactors=FALSE, header=TRUE)
head(my_data)
dim(my_data)
nrow(my_data)
ncol(my_data)
row.names(my_data) <- my_data$samples
head (my_data)
my_data <- my_data[, -1]
head(my_data)
data <- my_data/rowSums(my_data)
my_matrix <- as.matrix(data) 

heatmaply(data, xlab = "Features", ylab = "Transcription Factors", 
          scale = "column",
          main = "Data transformation using 'scale'",
          margins = c(60,100,40,20))

NOTE:

> head (my_data)
    samples   J1 J2 J3    H1    H2    H3
1   zf-C2H2 0.00  0  0 0.507 0.232 0.540
2     baz2a 0.00  0  0 0.355 0.342 0.132
3    baz2ab 0.00  0  0 0.091 0.070 0.163
4    kdm5ba 0.00  0  0 1.835 0.856 1.527
5      dbpa 0.00  0  0 5.344 5.355 0.000
6 LOC555983 0.02  0  0 0.294 0.634 0.835

NOTE2:

> my_data <- my_data[, -1]
> head(my_data)
    J1 J2 J3    H1    H2    H3
1 0.00  0  0 0.507 0.232 0.540
2 0.00  0  0 0.355 0.342 0.132
3 0.00  0  0 0.091 0.070 0.163
4 0.00  0  0 1.835 0.856 1.527
5 0.00  0  0 5.344 5.355 0.000
6 0.02  0  0 0.294 0.634 0.835

1 Answers1

1

You should add the first column to the row.names attribute (using the rownames function, yes, I know, it's not very consistent) before your remove it. That is:

rownames(my_data) <- my_data[, 1]
my_data <- my_data[, -1]
library(heatmaply)
heatmaply(my_data) # should now work

For the future - please remember that since you are asking people to give you help from their time (for free), you must show them first that you have made an effort to make the best use of their time that is possible. Hence, before you post there, please make sure you extend your question to include all the needed information so that people would answer it (specifically to have it include a SELF CONTAINED example). Please read two following guide on how a good question should be written, this will help to ensure that you will get the assistance you need in the future: http://stackoverflow.com/help/how-to-ask

Tal Galili
  • 24,605
  • 44
  • 129
  • 187