I have derived a list of deferentially expressed genes and would want to plot a heatmap of the expression values and see whether there the normal and tumor samples cluster out. Below is the code:
genes <- table$index
design <- model.matrix(~ 0+factor(c(data1$Class)))
colnames(design) <- c("S", "NS")
contrast.matrix <- makeContrasts(diff=NS-S, levels=design)
fit <- lmFit(tableSub, design = design) # What should the design be?
fit2 <- contrasts.fit(fit, contrast.matrix)
options(digits=3)
fit3 <- eBayes(fit2)
writefile = topTable(fit3, number=250, genelist=genes, adjust.method = "fdr", sort.by="B")
idx = rownames(writefile)
heatmap.2(exprs(gset)[idx,],trace='none',scale='row')
Now the columns I am getting are that of my samples. The samples can be grouped into "Normal" and "Tumour". How can I display this in the heatmap?
If you mean that you want a colour ('color', if you learned American English) bar, then you need to create a vector of colours that matches the columns in your gset object. This is then passed as the
ColSideColors
argument toheatmap.2()
. For example:If you mean that you want to split the heatmap columns (samples) into 2 groups, then take a look at THIS section of the ComplexHeatmap vignette. Column splitting can also be done in pheatmap
This is what I did after reading the comments. As you can see there patches of blue within the green bar. blue represents tumor and green represents normal. Is it possible to put all the blues on the left and the greens on the right?
Check the documentation of the tool to turn of clustering of the columns.
As an aside comment: much of those normals may be from stromal cells surrounding the primary tumour, in which case they likely exhibit 'tumourigenic' properties and are not quite normal at all. If this is TCGA data, then this heatmap pattern I have seen time and time again.