This is a test version of Biostars. For the public version, visit https://www.biostars.org.
heatmap in R

Hello friends I want to make a heatmap for gene data in R. this is the code:

geneExp <- read.table("file.txt",
                      header=T, sep="\t")
head(geneExp)

# Extract just the numeric data into a matrix with named rows by gene
rownames(geneExp) <- geneExp$Gene_ID
geneExp_matrix <- as.matrix(geneExp[3:317])
head(geneExp_matrix)
library(ComplexHeatmap)
library(pheatmap)
dev.off()
heatmap(geneExp_matrix,
        Rowv=NA, Colv=NA)

# Check if the RColorBrewer library is installed. If not, installs it, then loads it
if (!require("RColorBrewer")) {
  install.packages("RColorBrewer", dependencies = TRUE)
  library(RColorBrewer)
}

if (!require("gplots")) {
  install.packages("gplots", dependencies = TRUE)
  library(gplots)
}

dev.off()

if (!require("NMF")) {
  install.packages("NMF", dependencies = TRUE)
  library(NMF)
}

aheatmap(geneExp_matrix[,3:317], color = rev(brewer.pal(9,"RdBu")), scale="column", "row", annColors = "Set2", annRow=geneExp$type,Colv = NA,Rowv=NA)

I have this error: Error in geneExp_matrix[, 3:317] : subscript out of bounds

can anyone help me with this? Also, is the scaling correct?

gene

1 answer

Hi,

Assuming in your last line, that the a before the heatmap() function is a copy/paste mistake, the error that you got is related with the fact that you're trying to index columns that are outside the range of your matrix. What this means is that geneExp_matrix matrix does not have 317 columns.

Can you check this by doing:

dim(geneExp_matrix)

Then post your result, please. In principle the second no. should be <317, and that explains your problem.

António

rhasanvandj, can you provide some follow-up?

Log in to answer this question.