ComplexHeatmap繪制單個(gè)熱圖_第1頁
ComplexHeatmap繪制單個(gè)熱圖_第2頁
ComplexHeatmap繪制單個(gè)熱圖_第3頁
ComplexHeatmap繪制單個(gè)熱圖_第4頁
ComplexHeatmap繪制單個(gè)熱圖_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

第ComplexHeatmap繪制單個(gè)熱圖目錄前言一載入數(shù)據(jù),R包1.1載入ComplexHeatmap包1.2載入數(shù)據(jù)1.3繪制最簡單的熱圖二熱圖修飾2.1顏色1)連續(xù)型變量2)分類型變量2.2標(biāo)題1)設(shè)置行,列和圖例的標(biāo)題2)設(shè)置標(biāo)題的位置,顏色,字體,大小3)設(shè)置標(biāo)題的背景2.3聚類A:一般設(shè)置B:距離方法C:聚類方法D:聚類樹的渲染2.4設(shè)置行列順序

前言

ComplexHeatmap可以繪制很復(fù)雜的熱圖,能滿足日常以及文章所需,本次先簡單的介紹單個(gè)熱圖繪制的內(nèi)容。

單個(gè)熱圖由熱圖主體和熱圖組件組成。其中主體可分為行和列;組件可以是標(biāo)題、樹狀圖、矩陣名稱和熱圖注釋,在主圖的四周均可,且順序可調(diào)整。

一載入數(shù)據(jù),R包

1.1載入ComplexHeatmap包

#if(!requireNamespace("BiocManager",quietly=TRUE))

#install.packages("BiocManager")

#BiocManager::install("ComplexHeatmap")

library(ComplexHeatmap)

1.2載入數(shù)據(jù)

為更貼近生信使用場景,直接使用內(nèi)置的基因表達(dá)數(shù)據(jù)

expr=readRDS(paste0(system.file(package="ComplexHeatmap"),"/extdata/gene_expression.rds"))

#查看數(shù)據(jù)

str(expr)

expr[1:4,c(1:4,25:27)]

拿到一個(gè)新數(shù)據(jù)后,除了檢查[1:4,1:4]外,也許還需要看看最后幾列,另外還需要觀察列名稱的規(guī)律。

去除最后幾列,或者只選取列名字包含cell的(TCGA數(shù)據(jù)處理中也會經(jīng)常遇到)

mat=as.matrix(expr[,grep("cell",colnames(expr))])

1.3繪制最簡單的熱圖

Heatmap(mat)

可以看到有很多需要美化的地方,別急,一點(diǎn)點(diǎn)來。

二熱圖修飾

2.1顏色

1)連續(xù)型變量

可以使用circle::colorRamp2()函數(shù)來生成Heatmap()中的顏色映射函數(shù),輸入?yún)?shù)為分割位置以及分割點(diǎn)上的顏色。下例中,大于12的值都映射為紅色,小于12的值映射為綠色;

library(circlize)

#c中的范圍要根據(jù)實(shí)際情況設(shè)置

col_fun=colorRamp2(c(8,12,16),c("green","white","red"))

Heatmap(mat,name="mat",col=col_fun)

2)分類型變量

更改分類變量的顏色,需要把所有分類的數(shù)字均進(jìn)行賦值。

discrete_mat=matrix(sample(1:4,100,replace=TRUE),10,10)

colors=structure(1:4,names=c("1","2","3","4"))#black,red,green,blue

Heatmap(discrete_mat,name="mat",col=colors,

column_title="adiscretenumericmatrix")

更多顏色修改請參考官方文檔,文末的參考資料的鏈接。

2.2標(biāo)題

1)設(shè)置行,列和圖例的標(biāo)題

Heatmap(mat,

name="legendtitle",#圖例title

column_title="Iamacolumntitle",#列title

row_title="Iamarowtitle",

column_title_side="bottom")#行title

2)設(shè)置標(biāo)題的位置,顏色,字體,大小

Heatmap(mat,name="mat",

row_title="rowtitle",

row_title_rot=0,#旋轉(zhuǎn)方向

column_title="Iamabigcolumntitle",

column_title_side="bottom",#標(biāo)題位置

column_title_gp=gpar(fontsize=20,fontface="bold",col="red"))#顏色,字體,大小

3)設(shè)置標(biāo)題的背景

column_title_gp中的填充參數(shù)來設(shè)置標(biāo)題的背景顏色

Heatmap(mat,name="mat",

column_title="Iamacolumntitle",

column_title_gp=gpar(fill="red",col="white",border="blue"),

)

2.3聚類

聚類是熱圖可視化的關(guān)鍵組成部分,在ComplexHeatmap包中可以非常靈活的進(jìn)行設(shè)置。

A:一般設(shè)置

cluster_rows/columns:是否進(jìn)行聚類

show_column/row_dend:是否顯示聚類樹

column/row_dend_side:聚類圖繪制的位置

column_dend_height/row_dend_widht:聚類樹的高度和寬度

Heatmap(mat,name="mat",/codecodecluster_columns=T,/codecodecluster_rows=F,##turnoffrowclustering/codecodeshow_column_dend=T,##hidecolumndendrogram/codecodeshow_row_dend=F,/codecodecolumn_dend_side="top",#dendrogramlocation/codecodecolumn_dend_height=unit(4,"cm"))

注意:聚類樹的高度和寬度有區(qū)別。

B:距離方法

可選計(jì)算距離的方式包括pearson,spearman以及kendall,或者計(jì)算距離的自定義函數(shù)。

Heatmap(mat,name="mat",clustering_distance_rows="pearson",

column_title="pre-defineddistancemethod(1-pearson)")

自定義

Heatmap(mat,name="mat",clustering_distance_rows=function(x,y)1-cor(x,y),

column_title="afunctionthatcalculatespairwisedistance")

C:聚類方法

支持hclust()中的聚類方法。

Heatmap(mat,name="mat",clustering_method_rows="single")

D:聚類樹的渲染

根據(jù)聚類結(jié)果將聚類樹的枝設(shè)置不同的顏色

library(dendextend)/codecoderow_dend=as.dendrogram(hclust(dist(mat)))/codecoderow_dend=color_branches(row_dend,k=4)#`color_branches()`returnsadendrogramobject/codecodeHeatmap(mat,name="mat",/codecodecluster_rows=row_dend,/codecoderow_dend_width=unit(4,"cm"))

2.4設(shè)置行列順序

通過row_order/column_order函數(shù)自定義其排序,為方便展示選擇前30個(gè)基因。

mat-mat[1:30,]

Heatmap(mat,name="mat",

row_order=order(as.numeric(gsub("gene","",rownames(mat)))),#將gene1替換為1,在排序

column_order=sort(colnames(mat)),

column_title="reordermatrix")

注:此處將gene1,gene10先替換掉gene(不去的話是按照ASCII碼)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論