library(gplots)
setwd(‘/home/sun/SX/20180413_rnaseq/06_heatmap’)
getwd()
data <- read.table(’99_count_heatmap_input’,sep=’\t’,header=T,row.names = 1)
data=na.omit(data)
View(data)

# 將數(shù)據(jù)矩陣化
data <- as.matrix(data)
# 生成熱圖
heatmap.2(data)
# 優(yōu)化顏色
col=greenred
heatmap.2(data,col = greenred)
# 對數(shù)據(jù)進(jìn)行標(biāo)準(zhǔn)化:row(橫向,行),column(縱向,列)
heatmap.2(data,col = greenred,scale = “row”)
heatmap.2(data,col = greenred,scale = “column”)
## 去掉聚類數(shù):dendrogram=”none”
heatmap.2(data,col = greenred,scale = “row”,dendrogram=”none”)
# 只顯示行向量的聚類情況
heatmap.2(data,col = greenred,scale = “row”,dendrogram=”row”)
# 只顯示列向量的聚類情況 yes
heatmap.2(data,col = greenred,scale = “row”,dendrogram=”col”)
# 調(diào)控列向量,也就是x軸的label:srtCol=0(旋轉(zhuǎn)), adjCol = c(0.5,1)
heatmap.2(data,col = greenred,scale = “row”,dendrogram=”col”,srtCol=0, adjCol = c(0.5,1))
# 調(diào)控一下行向量,也就是y軸的label:srtRow=45(旋轉(zhuǎn))
heatmap.2(data,col = greenred,scale = “row”,dendrogram=”col”,srtCol=0, adjCol = c(0.5,1), srtRow=45, adjRow=c(0, 0.5))
# 設(shè)置 offsetRow/offsetCol 可以把label跟熱圖隔開!offsetRow=-1, offsetCol=-1
heatmap.2(data,col = greenred,scale = “row”,dendrogram=”col”,srtCol=0, adjCol = c(0.5,1), srtRow=45, adjRow=c(0, 0.5),offsetRow=1, offsetCol=1)
# 不需要圖標(biāo)時(shí)選擇key=F,density.info=c(‘none’)鍵值是否顯示波動信息
heatmap.2(data,col = greenred,scale = “row”,dendrogram=”col”, srtCol=0, adjCol = c(0.5,1), srtRow=45, adjRow=c(0, 0.5), offsetRow=1 , offsetCol=1,key=F)
# 需要圖標(biāo)時(shí)選擇key=T,keysize(表示圖標(biāo)大小)
heatmap.2(data,col = greenred,scale = “row”,dendrogram=”col”, srtCol=0, adjCol = c(0.5,1), srtRow=45, adjRow=c(0, 0.5), offsetRow=1 , offsetCol=1,key=T,keysize = 1.8)
# 是否需要基準(zhǔn)線(圖上青色的線條)
# trace=”none”
# 需要時(shí)輸入”both”,”row” 或者”column”
heatmap.2(data,col = greenred,scale = “row”,dendrogram=”col”, srtCol=0, adjCol = c(0.5,1), srtRow=45, adjRow=c(0, 0.5), offsetRow=1 , offsetCol=1,key=T,keysize = 1.8,trace=”none”)
# 定義xlab和ylab的字符大小:
# cexCol=1,cexRow=1
heatmap.2(data,col = greenred,scale = “row”,dendrogram=”col”, srtCol=0, adjCol = c(0.5,1), srtRow=45, adjRow=c(0, 0.5), offsetRow=1 , offsetCol=1,key=T,keysize = 1.8,trace=”none”,cexCol=1,cexRow=1)
# R布局:
# lty。直線類型0為空,1為實(shí)線,2為虛線,3為點(diǎn)線
# pch。表示點(diǎn)的形狀,1代表圓圈,2代表三角形,3代表“+”號
# bty。限定圖形的邊框類型。值為”o”(默認(rèn))、”l”、”7″、”c”、”u”或者”]”中的任意一個(gè),對應(yīng)的邊框類型就和該字母的形狀相似。
# pty。表示當(dāng)前繪圖區(qū)域的形狀,”s”表示生成一個(gè)正方形區(qū)域,”m”表示生成最大的繪圖區(qū)域
# plt。形式為c(x1, x2, y1, y2),設(shè)定當(dāng)前的繪圖區(qū)域。
# rep就是復(fù)制數(shù)據(jù),replication 。rep(x,times),x為要復(fù)制的數(shù)據(jù) times是要重復(fù)的次數(shù)。
# mar=c(4,3,2,1),與外圍邊距的設(shè)置類似,是指繪圖邊距分別為下邊距:4行,左邊距3行,上邊距2行,右邊距1行
op <- par(mar = rep(0, 4))
op <- par(mar = c(20,0,0,0))
plot.new()
par(op)
# 行列的排列順序是否默認(rèn),F是原順序
# Rowv = F
# Colv =F
# 更改畫圖位置
lmat <- rbind( c(5,3,4), c(2,1,4))
lhei <- c(1.5,4)
lwid <- c(1.5,4,0.75)
# 默認(rèn)畫圖位置
lmat <- rbind(4:3,2:1)
lhei <- c(1.5,4)
lwid <- c(1.5,4)
##
heatmap.2(data,
col = greenred,
Rowv = F, Colv =F,
trace=”none”,
scale = “row”,
dendrogram=”col”,
labRow = ” “,
cexCol=1,cexRow=0.5,
offsetRow=1, offsetCol=1.8,
srtCol=30, adjCol = c(0.5,1), srtRow=30, adjRow=c(0, 0.5),
margins=c(5,3),
key=T,keysize = 1.5,density.info=c(‘none’),
main=”log2foldchange Heatmap”)
## 最終命令
heatmap.2(data,col = greenred,scale = 'row',dendrogram='none',srtCol=0, adjCol = c(0.5,1), srtRow=0, adjRow=c(0, 0.5),offsetRow=1, offsetCol=1,density.info=c('none'),trace='none',cexCol=1.5,cexRow=0.9,Rowv = F,Colv =F,main = "Heatmap")