Home
News
Feed
search engine
by
freefind
advanced
code I could use as a template for heatmap dot 2 for my own data 11-13-2014d1019
2015-04-13
code I could use as a template for heatmap dot 2 for my own data 11-13-2014d1019 code modified from here http://www.molecularecologist.com/2013/08/making-heatmaps-with-r-for-microbiome-analysis/ Note the last time I tried to run this heatmap code, I received the following error: 04-13-2015d1750 { Error in heatmap.2(as.matrix(all.data), Rowv = as.dendrogram(row.clus), : object 'var1' not found } Does this code cluster both rows and columns? Yes What should the form of the input data look like? { sample Acetivibrio Acetobacter Achromobacter 1 S7 0 5 0 2 S8 1 0 1 3 S9 0 3 1 } What should be changed in the code for it to work with your specific data? { Note that the data should be in csv format change the line with row.names(all.data) <- all.data$sample so that "sample" is replaced with the title of your different rows. change the line with all.data <- read.csv("C:/Sync/pDR/2014/2014/06-26-2014d0006/test_file4.csv") # load the data so that it reads your data file } code to make heatmap in R library(gplots) # for heatmap.2 # to install packages from Bioconductor: source("http://bioconductor.org/biocLite.R") biocLite("Heatplus") # annHeatmap or annHeatmap2 library(Heatplus) # load the vegan package for hierachical clustering if you want to use distance functions not specified in dist. library(vegan) # load the RColorBrewer package for better colour options library(RColorBrewer) all.data <- read.csv("C:/Sync/pDR/2014/2014/06-26-2014d0006/test_file4.csv") # load the data dim(all.data) row.names(all.data) <- all.data$sample all.data <- all.data[, -1] # colorRampPalette is in the RColorBrewer package. This creates a colour palette that shades from light yellow to red in RGB space with 100 unique colours scaleyellowred <- colorRampPalette(c("lightyellow", "red"), space = "rgb")(100) # calculate the Bray-Curtis dissimilarity matrix on the full dataset: data.dist <- vegdist(all.data, method = "bray") # Do average linkage hierarchical clustering. Other options are 'complete' or 'single'. You'll need to choose the one that best fits the needs of your situation and your data. row.clus <- hclust(data.dist, "aver") # you have to transpose the dataset to get the genera as rows data.dist.g <- vegdist(t(all.data), method = "bray") col.clus <- hclust(data.dist.g, "aver") # make the heatmap with Rowv = as.dendrogram(row.clus) heatmap(as.matrix(all.data), Rowv = as.dendrogram(row.clus), Colv = as.dendrogram(col.clus), col = scaleyellowred, margins = c(10, 3)) heatmap.2(as.matrix(all.data), Rowv = as.dendrogram(row.clus), Colv = as.dendrogram(col.clus), col = scaleyellowred, RowSideColors = var1, margins = c(11, 5), trace = "none", density.info = "none", xlab = "genera", ylab = "Samples", main = "Heatmap example", lhei = c(2, 8)) # this makes the colour-key legend a little thinner
azim58wiki: