How to plot gene expression heatmap based on groups in R
1
0
Entering edit mode
4.8 years ago
Gene_MMP8 ▴ 240

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?


RNA-Seq R • 11k views
ADD COMMENT
2
Entering edit mode

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 to heatmap.2(). For example:

colnames(gset)
'tumour1' 'tumour2' 'normal1' 'tumour3' 'normal2'

myColours <-  c('red3', 'red3', 'royalblue', 'red3', 'royalblue')

heatmap.2(..., ColSideColors = myColours, ...)

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

ADD REPLY
0
Entering edit mode

enter image description here

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?

ADD REPLY
0
Entering edit mode

Check the documentation of the tool to turn of clustering of the columns.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
3
Entering edit mode
4.8 years ago
ATpoint 82k

I suggest you extensively read the documentation of ComplexHeatmap at Bioconductor. It is outstandingly comprehensive with a lot of example code for all kinds of visualizations including heatmaps. Has a lot of convenience-functions such as extracting genes belonging to clusters based on hlcust etc. See https://jokergoo.github.io/ComplexHeatmap-reference/book/

ADD COMMENT

Login before adding your answer.

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