Making Heatmaps: Difference between revisions

From Powers Wiki
No edit summary
No edit summary
 
(15 intermediate revisions by 5 users not shown)
Line 1: Line 1:
'''(Group Note: Heatmaps could be added in octave code.)'''
==Load the data==
==Load the data==
The data can be prepared in csv or text file to load the data in to R. For example, to load ''list.csv'':
The data can be prepared in csv or text file to load the data in to R. For example, to load ''list.csv'':


  data <- read.csv (“list.csv”)
  heatmapname <- read.csv (“list.csv”)
 
The "file directory" can be easily found by dragging the file to the active window of R, then it will be shown with an error report. Ignore the error, but copy and paste the file directory.


==Name the rows==
==Name the rows==
You can then name the rows of the heatmap like so:
You can then name the rows of the heatmap like so:


  Row.names(data) <- data$Name
  row.names(heatmapname) <- data$Name


To exclude the first column from the heat map, use a command of similar form to the following:
To exclude the first column from the heat map, use a command of similar form to the following:


  Type:Data <- data [,2: n]
  heatmapname <- heatmapname [,2: n]


In the above command, '''n''' is the number of columns to be included in the heat map.
In the above command, '''n''' is the number of columns to be included in the heat map.
Another simpler way is to combine this step with the file importation by adding two command after the import:
row.names=1, header=TRUE


==Build a data matrix==
==Build a data matrix==
Use the following command to build a data matrix for making the heat map:
Use the following command to build a data matrix for making the heat map:


  Data_matrix <- data.matrix (data)
  heatmapname_matrix <- data.matrix (heatmapname)


==Plot the heat map==
==Plot the heat map==
Line 27: Line 33:
To make heat map, run the following command:
To make heat map, run the following command:


  heatmap.2 (Data_matrix, dendrogram="row", col= redgreen (75), scale="none", key = TRUE, keysize = 1.0, margins = c(4,30),  density.info="none", trace="none")
  heatmap.2 (heatmapname_matrix, dendrogram="row", col= redgreen (75), scale="none",
key = TRUE, keysize = 1.0, margins = c(4,30),
  density.info="none", trace="none")
 
'''Note: To rescale the color key, add break function to the heatmap.2. '''
 
'''breaks=c(seq(-1,0.8,length=10),seq(0.8,1.2,length=10),seq(1.2,3,length=10),'''
 
This will define the color range:
 
"red=[-1,0.8]
 
black=[0.8,1.2]
 
green=[1.2,3]"
 
 
[[category:Data_Processing_and_Analysis]]
 
==Run from text file==
'''Note: It is also possible to write all the steps in txt file as a single script.'''
===Open the script ===
* In the file menu click open script
** Choose the proper directory and script file name
** The script file will be opened in the R Editor window
** If necessary changes can be made on the R Editor window


[[Category:Protocols]]
===Run the script ===
* Click Run all or Run line or selection form the Edit menu

Latest revision as of 05:05, 20 January 2022

(Group Note: Heatmaps could be added in octave code.)

Load the data

The data can be prepared in csv or text file to load the data in to R. For example, to load list.csv:

heatmapname <- read.csv (“list.csv”)

The "file directory" can be easily found by dragging the file to the active window of R, then it will be shown with an error report. Ignore the error, but copy and paste the file directory.

Name the rows

You can then name the rows of the heatmap like so:

row.names(heatmapname) <- data$Name

To exclude the first column from the heat map, use a command of similar form to the following:

heatmapname <- heatmapname [,2: n]

In the above command, n is the number of columns to be included in the heat map.

Another simpler way is to combine this step with the file importation by adding two command after the import:

row.names=1, header=TRUE

Build a data matrix

Use the following command to build a data matrix for making the heat map:

heatmapname_matrix <- data.matrix (heatmapname)

Plot the heat map

Note: Gnuplot package must be installed in R before heat maps may be displayed! Run the following command to load in the gplots library.

library("gplots")

To make heat map, run the following command:

heatmap.2 (heatmapname_matrix, dendrogram="row", col= redgreen (75), scale="none",
key = TRUE, keysize = 1.0, margins = c(4,30),
density.info="none", trace="none")

Note: To rescale the color key, add break function to the heatmap.2.

breaks=c(seq(-1,0.8,length=10),seq(0.8,1.2,length=10),seq(1.2,3,length=10),

This will define the color range:

"red=[-1,0.8]

black=[0.8,1.2]

green=[1.2,3]"

Run from text file

Note: It is also possible to write all the steps in txt file as a single script.

Open the script

  • In the file menu click open script
    • Choose the proper directory and script file name
    • The script file will be opened in the R Editor window
    • If necessary changes can be made on the R Editor window

Run the script

  • Click Run all or Run line or selection form the Edit menu