-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeatMaps from Packtpub-Part 2.Rmd
90 lines (78 loc) · 2.29 KB
/
HeatMaps from Packtpub-Part 2.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
title: "Heatmap Part 2"
output: html_document
---
#Part 2
##Getting ready
Download the script 5644OS_02_01.r and the data sets gene_expression.txt, runners.csv, and apple_stocks.xlsx from your account at http://www.packtpub.com and save them to your hard drive.
##How to do it...
Note: I have commented some code out because I will not install JAVA requires to support the XLSX pacakge.
```{r}
# if you are running the script from a different location
# than the location of the data sets, uncomment the
# next line and point setwd() to the data set location
# setwd("/home/username/Datasets")
### loading packages
if (!require("gplots")) {
install.packages("gplots", dependencies = TRUE)
library(gplots)
}
if (!require("lattice")) {
install.packages("lattice", dependencies = TRUE)
library(lattice)
}
# if (!require("xlsx")) {
# install.packages("xlsx", dependencies = TRUE)
# library(xlsx)
# }
pdf("readingData.pdf")
### loading data and drawing heat maps
# 1) gene_expression.txt
gene_data <- read.table("../data/gene_expression.txt",
comment.char = "/",
blank.lines.skip = TRUE,
header = TRUE,
sep = "\t",
nrows = 20)
gene_data <- data.matrix(gene_data)
gene_ratio <- outer(gene_data[,"Treatment"],
gene_data[,"Control"],
FUN = "/")
heatmap.2(gene_ratio,
xlab = "Control",
ylab = "Treatment",
trace = "none",
main = "gene_expression.txt")
# 2) runners.csv
runner_data <- read.csv("../data/runners.csv")
rownames(runner_data) <- runner_data[,1]
runner_data <- data.matrix(runner_data[,2:ncol(runner_data)])
colnames(runner_data) <- c(2003:2012)
runner_data[runner_data == 0.00] <- NA
heatmap.2(runner_data,
dendrogram = "none",
Colv = NA,
Rowv = NA,
trace = "none",
na.color = "gray",
main = "runners.csv",
margin = c(8,10))
# # 3) apple_stocks.xlsx
# stocks_table <- read.xlsx("../data/apple_stocks.xlsx",
# sheetIndex = 1,
# rowIndex = c(1:28),
# colIndex = c(1:5,7))
# row_names <- (stocks_table[,1])
# stocks_matrix <- data.matrix(
# stocks_table[2:ncol(stocks_table)])
# rownames(stocks_matrix) <- as.character(row_names)
# stocks_data = t(stocks_matrix)
# print(levelplot(stocks_data,
# col.regions = heat.colors,
# margin = c(10,10),
# scales = list(x = list(rot = 90)),
# main = "apple_stocks.xlsx",
# ylab = NULL,
# xlab = NULL))
dev.off()
```