Thanks a lot! It worked perfectly!
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!
1 answer
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))
Log in to answer this question.