Generating multiple heatmaps with heatmap3 and lapply
1
0
Entering edit mode
2.4 years ago
Marco Pannone ▴ 790

Hey everybody

I have a series of .csv files from RNA-seq data stored in a list and I am trying to produce a heatmap for each of them by using heatmap3 function combined with lapply in R, after first converting each of them to a matrix.

I am try running this chunk of code, but without success:

heatmaps <- lapply(list, function(x) { 
genes_heatmap <- as.matrix(x)
heatmap3(genes_heatmap, margins=c(5,8), cexRow = 0.1, cexCol = 0.8, showRowDendro = TRUE, ColSideWidth = 0.8, Colv = NA, Rowv = T)
})

it seems like it keeps running but it does not produce any result. I was expecting to obtain all the heatmaps stored in a large list returned by lapply, but it does not seem the case.

I would like to successfully generate all the heatmaps and save them as .pdf files, each of them separately.

Thanks in advance!

heatmap3 rstudio heatmaps lapply • 718 views
ADD COMMENT
3
Entering edit mode
2.4 years ago
seidel 11k

heatmap3 simply returns information describing aspects of the heat map, but not the heat map image. You could insert code to save the pdf, and use the mapply function to add a second variable to help generate unique filenames:

# generate a list of matrices
mylist <- list(foo1=matrix(rnorm(100), 10,10),
               foo2=matrix(rnorm(100), 10,10),
               foo2=matrix(rnorm(100), 10,10))

# make and save heat maps
mapply(function(x, y){
  pdf(file=paste0("heatmap", y, ".pdf"))
  heatmap3(x)
  dev.off()
}, mylist, seq_along(mylist))
ADD COMMENT
0
Entering edit mode

Thanks a lot! It worked perfectly!

ADD REPLY

Login before adding your answer.

Traffic: 2685 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