综合图区亚洲网友自拍|亚洲黄色网络|成人无码网WWW在线观看,日本高清视频色视频kk266,激情综合五月天,欧美一区日韩一区中文字幕页

English | 中文版 | 手機(jī)版 企業(yè)登錄 | 個(gè)人登錄 | 郵件訂閱
當(dāng)前位置 > 首頁 > 技術(shù)文章 > 一文教您如何輕松繪制Circos圖——環(huán)形熱圖

一文教您如何輕松繪制Circos圖——環(huán)形熱圖

瀏覽次數(shù):2716 發(fā)布日期:2021-11-25  來源:本站 僅供參考,謝絕轉(zhuǎn)載,否則責(zé)任自負(fù)

圈圖在生信分析可視化中十分常見,而circos軟件的使用較為復(fù)雜,在這里分享R包「circlize」[1]的circos.heatmap函數(shù),用于繪制環(huán)形熱圖。

該包的詳細(xì)說明文件見:https://jokergoo.github.io/circlize_book/book/introduction.html#principle-of-design
 
 
無腦復(fù)制代碼繪圖

```

##代碼1(標(biāo)準(zhǔn)化圈圖)

##安裝包

install.packages("dendextend","circlize","openxlsx")

##加載包

library(circlize)

library(dendextend)

library(openxlsx)

##讀入數(shù)據(jù)

mat1 <- read.xlsx("C:\\Users\\user\\Desktop\\工作空間\\熱圖\\data.xlsx")##讀入xlsx表

#((C:\\Users\\xyf\\Desktop\user\工作空間\\熱圖\\data.xlsx)替換為你的數(shù)據(jù)的路徑)

row.names(mat1)<-mat1[,1]#修改行名

mat1<-mat1[,-1]##刪除第一列,使之變?yōu)閿?shù)字矩陣,繪圖的數(shù)據(jù)要求為矩陣(也就是單一類型的數(shù)據(jù)矩陣,這里全為數(shù)字)

##繪圖

col_fun1 = colorRamp2(c(-2, 0, 2), c("blue", "white", "red"))##設(shè)置熱圖顏色

column_od = hclust(dist(t(mat1)))$order #對(duì)列聚類

circos.par(gap.after = c(10))##為添加列名留出空間

circos.heatmap(mat1[, column_od], ##將列聚類后重新排序的矩陣

               col = col_fun1, ##設(shè)置顏色

               dend.side = "inside",##樹狀圖在圈內(nèi)

               rownames.side = "outside",##行名在圈外

               dend.track.height = 0.2,

               dend.callback = function(dend, m, si) {

                 # when k = 1, it renders one same color for the whole dendrogram

                 color_branches(dend, k = 4, col = 2:5)##對(duì)樹狀圖進(jìn)行著色

               }

)

circos.track(track.index = 2, ##將列名添加在第二個(gè)軌道(就是熱圖所在的環(huán)形軌道)

             panel.fun = function(x, y) {

               if(CELL_META$sector.numeric.index == 1) { # the last sector

                 cn = colnames(mat1[, column_od])##取得列名

                 n = length(cn)

                 circos.text(rep(CELL_META$cell.xlim[2], n) + convert_x(1, "mm"), ##x軸坐標(biāo)

                             1:n - convert_y(0.5, "mm"), ##y軸坐標(biāo)

                             cn, ##輸入要展示的列名

                             cex = 0.25, ##列名的大小

                             adj = c(0, 0.5),

                             facing = "inside")

               }

             }, bg.border = NA)

 

circos.clear()

```

細(xì)致講解

第一步:準(zhǔn)備輸入數(shù)據(jù)。
一般用熱圖展示基因在樣本中的表達(dá)變化,代碼中data.xlsx為輸入文件,格式圖1。
 

圖1

第二步:安裝軟件(R和Rstudio)和包("dendextend","circlize","openxlsx")。
從這兩個(gè)網(wǎng)址https://cran.r-project.org/bin/windows/base/R-4.1.2-win.exe和https://download1.rstudio.org/desktop/windows/RStudio-2021.09.1-372.exe(復(fù)制到瀏覽器即可打開)下載軟件,直接雙擊安裝,所有選項(xiàng)默認(rèn)。

用下面的代碼2安裝三個(gè)包。

```

##代碼2

 

##安裝分析包

install.packages("dendextend","circlize","openxlsx")

##加載包

library(circlize)

library(dendextend)

library(openxlsx)

```

第三步:代碼參數(shù)調(diào)整。
1> 修改顏色,使用代碼3,結(jié)果見圖2
。顏色編號(hào)("#26B9CB", "#FFFFFF", "#B72865")可以在該網(wǎng)址:https://htmlcolorcodes.com/ 隨意選擇。

```

##代碼3

col_fun1 = colorRamp2(c(-2, 0, 2), c("#26B9CB", "#FFFFFF", "#B72865"))##設(shè)置熱圖顏色

column_od = hclust(dist(t(mat1)))$order #對(duì)列聚類

circos.par(gap.after = c(10))##為添加列名留出空間

circos.heatmap(mat1[, column_od], ##將列聚類后重新排序的矩陣

               col = col_fun1, ##設(shè)置顏色

               dend.side = "inside",##樹狀圖在圈內(nèi)

               rownames.side = "outside",##行名在圈外

               dend.track.height = 0.2,

               dend.callback = function(dend, m, si) {

                 # when k = 1, it renders one same color for the whole dendrogram

                 color_branches(dend, k = 4, col = 2:5)##對(duì)樹狀圖進(jìn)行著色

               }

)

circos.track(track.index = 2, ##將列名添加在第二個(gè)軌道(就是熱圖所在的環(huán)形軌道)

             panel.fun = function(x, y) {

               if(CELL_META$sector.numeric.index == 1) { # the last sector

                 cn = colnames(mat1[, column_od])##取得列名

                 n = length(cn)

                 circos.text(rep(CELL_META$cell.xlim[2], n) + convert_x(1, "mm"), ##x軸坐標(biāo)

                             1:n - convert_y(0.5, "mm"), ##y軸坐標(biāo)

                             cn, ##輸入要展示的列名

                             cex = 0.25, ##列名的大小

                             adj = c(0, 0.5),

                             facing = "inside")

               }

             }, bg.border = NA)

 

circos.clear()

```


圖2
 

2> 修改文字的大小(rownames.cex)。字體(rownames.font)和顏色(rownames.col),使用代碼4,結(jié)果見圖3。

 

```

##代碼4

col_fun1 = colorRamp2(c(-2, 0, 2), c("#26B9CB", "#FFFFFF", "#B72865"))##設(shè)置熱圖顏色

column_od = hclust(dist(t(mat1)))$order #對(duì)列聚類

circos.par(gap.after = c(15))##為添加列名留出空間

circos.heatmap(mat1[, column_od], ##將列聚類后重新排序的矩陣

               col = col_fun1, ##設(shè)置顏色

               dend.side = "inside",##樹狀圖在圈內(nèi)

               rownames.side = "outside",##行名在圈外

               rownames.col = 1:nrow(mat1) %% 10 + 1,##行名添加顏色

               rownames.cex = runif(nrow(mat1), min = 0.3, max = 2),##行名的大小

               rownames.font = 1:nrow(mat1) %% 4 + 1,##行名字體

               dend.track.height = 0.2,

               dend.callback = function(dend, m, si) {

                 # when k = 1, it renders one same color for the whole dendrogram

                 color_branches(dend, k = 4, col = 2:5)##對(duì)樹狀圖進(jìn)行著色

               }

)

circos.track(track.index = 2, ##將列名添加在第二個(gè)軌道(就是熱圖所在的環(huán)形軌道)

             panel.fun = function(x, y) {

               if(CELL_META$sector.numeric.index == 1) { # the last sector

                 cn = colnames(mat1[, column_od])##取得列名

                 n = length(cn)

                 circos.text(rep(CELL_META$cell.xlim[2], n) + convert_x(1, "mm"), ##x軸坐標(biāo)

                             1:n - convert_y(0.5, "mm"), ##y軸坐標(biāo)

                             cn, ##輸入要展示的列名

                             cex = 0.25, ##列名的大小

                             adj = c(0, 0.5),

                             facing = "inside")

               }

             }, bg.border = NA)

 

circos.clear()

```

圖3
 
來源:上海百趣生物醫(yī)學(xué)科技有限公司
聯(lián)系電話:021-61531195
E-mail:chengyichun@biotree.cn

用戶名: 密碼: 匿名 快速注冊(cè) 忘記密碼
評(píng)論只代表網(wǎng)友觀點(diǎn),不代表本站觀點(diǎn)。 請(qǐng)輸入驗(yàn)證碼: 8795
Copyright(C) 1998-2024 生物器材網(wǎng) 電話:021-64166852;13621656896 E-mail:info@bio-equip.com