Question: How to plot gene expression heatmap based on groups in R
0
gravatar for banerjeeshayantan
20 months ago by
banerjeeshayantan190 wrote:

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 • 3.1k views
ADD COMMENTlink modified 20 months ago • written 20 months ago by banerjeeshayantan190
2

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 REPLYlink modified 20 months ago • written 20 months ago by Kevin Blighe71k

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 REPLYlink modified 20 months ago by ATpoint46k • written 20 months ago by banerjeeshayantan190

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

ADD REPLYlink written 20 months ago by ATpoint46k

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 REPLYlink modified 20 months ago • written 20 months ago by Kevin Blighe71k
3
gravatar for ATpoint
20 months ago by
ATpoint46k
ATpoint46k wrote:

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 COMMENTlink written 20 months ago by ATpoint46k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 975 users visited in the last hour
_