heatmap in R
1
0
Entering edit mode
3.8 years ago
Rob ▴ 170

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 • 710 views
ADD COMMENT
1
Entering edit mode
3.8 years ago

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

ADD COMMENT
0
Entering edit mode

rhasanvandj, can you provide some follow-up?

ADD REPLY

Login before adding your answer.

Traffic: 2934 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6