How to create a heatmap of RNA-Seq Data in R?
1
1
Entering edit mode
5.6 years ago
ishackm ▴ 110

Hi all,

I have the following RNA-Seq dataset:

An example row of the dataset:

ID          Gene.ID     Gene.symbol   logFC       AveExpr     t          P.Value    adj.P.Val
223597_at   55600       ITLN1         -9.669889   0.8438350   -50.27410  3.61e-60   1.98e-55

I would like to create a heatmap of these genes in the whole dataframe and also then create a heatmap with just selected number of genes in the dataframe in R.

Can you please help me with this?

Many Thanks,

Ishack

RNA-Seq r heatmap • 22k views
ADD COMMENT
2
Entering edit mode

ComplexHeatmap is a great R package to create heatmaps.

ComplexHeatmap examples

ADD REPLY
1
Entering edit mode

You probably want to use a table of expression values, not stats.

ADD REPLY
0
Entering edit mode

Hints to help you get started: You need a bunch of geom_rects with fill=logFC and a manual gradient color scale with high=red, low=blue, middle=white

ADD REPLY
0
Entering edit mode

Hi All, Thanks very much for your help,

I found a way finally to create a heatmap for the RNA-seq data.

But I how can I group the different samples into the 2 different groups and compare them, please?

   Gene.Symbol  GSM997591  GSM997592  GSM997593  GSM997594   GSM997595
1 18S ribosomal RNA 2.13784980  2.5907211 1.64000610  2.3885298  2.17460160
2 28S ribosomal RNA 0.02856135  0.1421256 0.01333952 -0.1594081  0.03220868
3 A1BG               0.41368390 -0.0319581 0.33633804  0.6772432  0.12198353

GSM997591 GSM997592 = Control

GSM997593 GSM997594 GSM997595 = Disease

I have chosen to use the raw expression values as recommended.

x-axis = experimental groups

y axis = axis gene name

Any help would be greatly appreciated.

Ishack

ADD REPLY
1
Entering edit mode

you may get some help from this post

ADD REPLY
0
Entering edit mode

Hi Prakash,

That post is a bit useful but very hard to understand, can you please give me some code examples?

Many Thanks,

Ishack

ADD REPLY
1
Entering edit mode

When you group observations, you're going to need to aggregate the values somehow. Pick an aggregation logic (mean/median/something that makes sense) and plot that. I do sense you're already losing sight of what's important when you plot a heatmap. When you group and plot an aggregate, your plot will in no way help derive insights into your data. It can only be used to visualize obvious disparities between the groups.

ADD REPLY
0
Entering edit mode

Thanks RamRS for the insight.

ADD REPLY
0
Entering edit mode

Stop adding new posts as answers unless you’re actually posting a solution to the question.

ADD REPLY
0
Entering edit mode

https://ibb.co/Wz6wfyX

Hi Guys, this is the heatmap I have created. Can you tell me please if this is biologically meaningful?

Many Thanks,

Ishack

ADD REPLY
1
Entering edit mode

Is this an assignment of some sort? Why are you seeking help with both creating the heatmap and interpreting it? Also, please see How to add images to a Biostars post to add the image properly. You need the direct link to the image, not the link to the webpage that has the image embedded (which is what you have used here)

ADD REPLY
0
Entering edit mode

Apologies, this is not an assignment. I just need help creating the heatmap. I just wanted your opinion on how it looks visually.

ADD REPLY
1
Entering edit mode

We know essentially nothing about your experiment, how could we tell you what’s biologically meaningful?

ADD REPLY
0
Entering edit mode
  1. Make the annotation of your columns and rows (a.k.a sample list) ,
  2. use clustering for both of your rows and columns, dendrogram function in the heatmap code is from hclust, or if its pheatmap r function then they have some functions like clustering method
  3. label your samples and then plot the heatmap. You should be able to tell it yourself if this is biologically relevant.

Here I can see some faint signal but clustering of columns and rows needed to really see if you have a proper separation of your data across meaningful biological condition of interest. Again if you are new, scan the blogs well to see a tutorial, there are plenty floating in biostars and some amazing blog posts of real data using various R packages for heatmap visualization with code snippets.

ADD REPLY
1
Entering edit mode
5.6 years ago

I would recommending searching for this - there are many tutorials and examples available.

gplots' heatmap.2 function is very flexible and relatively easy to use.

But I have to ask, what do you expect this heatmap to show you? It's going to just be a single column of log fold changes. Looking at actual expression values across samples would be much more informative.

ADD COMMENT
0
Entering edit mode

Can you give me example code please?

Im very new to this.

Many Thanks,

Ishack

ADD REPLY
1
Entering edit mode

As @RamRS said, there are many examples available through Google. Here is one with a simple example along with in-depth explanations to get you started.

ADD REPLY
0
Entering edit mode

Start with just heatmap.2(x) and then, based on what needs to be customized, look for an optional argument that makes sense and change its value. Need a title for the plot? Add main = "Plot Title" to make the function call now heatmap.2(x, main = "Plot Title"). Repeat this exercise (using Google liberally) and you will learn "new" stuff the way most of us learn.

ADD REPLY
0
Entering edit mode

Hi all, I have created a heatmap in R but I am still having difficulties labelling the samples into the two different groups (Control vs Treatment)on the heatmapp with a key included.

This is the R code so far:

data = read.csv("../Data/test3.csv", header = TRUE,row.names = 1)
data
mat=data.matrix(data, rownames.force = NA)
heatmap(mat, main = "MOCS Vs MOTEC", xlab = "Samples", ylab = "DEG")

heatmap

The annotated datasetenter image description here

How can differentiate between the sample groups on the heatmap and also provide a key, please?

Please note I am very new to this so if you can provide code examples, that would be greatly appreciated.

I would like the final heatmap to look like this, please

The desired result: https://i.ibb.co/4FdGnwz/1555438568827-793023657.png

Many Thanks,

Ishack

ADD REPLY
0
Entering edit mode

The data as you have it right now is pretty wonky, given that you store information about the samples in the header.

You will need to remove the Control/Treatment double header from your data, convert it from its current wide-form state to long-form (look into reshape2::melt or tidyr::gather, as shown here), then add a column that contains the Control/Treatment information and use that column with a facet function. Look into facet_wrap and facet_grid, that will get you to what you need.

Please try as much as you can before asking us for code examples.

ADD REPLY
0
Entering edit mode

Hi Ram,

Thanks for your advice.

I used the code from this Biostars post: pheatmap annotation - legend only for columns

data = read.csv("../Data/test3.csv", header = TRUE,row.names = 1)
data

  metadata <- data.frame(
  c(rep("Treatment", ncol(data)/4), rep("Control")),
  row.names=colnames(data))
colnames(metadata) <- c("condition")
metadata

How can I use this code to annotate the samples? The columns are in order.

Many Thanks,

Ishack

ADD REPLY
0
Entering edit mode

Please Google add column to data.frame r. You don't need a new metadata data frame, just a simple cbind. And make sure you're adding stringsAsFactors = FALSE to all read.table variants (which in your case is read.csv) unless you have good reason not to.

ADD REPLY

Login before adding your answer.

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