玩朋友的丰满人妻,朋友的丰满人妻中文字幕,从后面挺进邻居丰满少妇

新聞資訊

NEWS

實用干貨 | 輕松繪制Circos圖——環形熱圖

分類:公司動態   發布時間 2021-11-22   閱讀: 160

不會代碼的朋友也能畫漂亮的熱圖,不要走。!

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


該包的詳細說明文件見:https://jokergoo.github.io/circlize_book/book/introduction.html#principle-of-design

無腦復制代碼繪圖

```

##代碼1(標準化圈圖)

##安裝包

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

##加載包

library(circlize)

library(dendextend)

library(openxlsx)

##讀入數據

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

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

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

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

##繪圖

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

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

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

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

               col = col_fun1, ##設置顏色

               dend.side = "inside",##樹狀圖在圈內

               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)##對樹狀圖進行著色

               }

)

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

             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軸坐標

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

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

                             cex = 0.25, ##列名的大小

                             adj = c(0, 0.5),

                             facing = "inside")

               }

             }, bg.border = NA)

 

circos.clear()

```

細致講解

第一步:準備輸入數據。

一般用熱圖展示基因在樣本中的表達變化,代碼中data.xlsx為輸入文件,格式見圖1。


 圖1


第二步:安裝軟件(R和Rstudio)和包("dendextend","circlize","openxlsx")。

從這兩個網址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(復制到瀏覽器即可打開)下載軟件,直接雙擊安裝,所有選項默認。

用下面的代碼2安裝三個包。

```

##代碼2

 

##安裝分析包

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

##加載包

library(circlize)

library(dendextend)

library(openxlsx)

```


第三步:代碼參數調整。

1> 修改顏色,使用代碼3,結果見圖2。顏色編號("#26B9CB", "#FFFFFF", "#B72865")可以在該網址:https://htmlcolorcodes.com/ 隨意選擇。

```

##代碼3

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

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

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

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

               col = col_fun1, ##設置顏色

               dend.side = "inside",##樹狀圖在圈內

               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)##對樹狀圖進行著色

               }

)

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

             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軸坐標

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

                             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,結果見圖3。

```

##代碼4

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

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

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

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

               col = col_fun1, ##設置顏色

               dend.side = "inside",##樹狀圖在圈內

               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)##對樹狀圖進行著色

               }

)

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

             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軸坐標

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

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

                             cex = 0.25, ##列名的大小

                             adj = c(0, 0.5),

                             facing = "inside")

               }

             }, bg.border = NA)

 

circos.clear()

```


圖3

 參考文獻

[1] Gu, Z. (2014) circlize implements and enhances circular visualization in R. Bioinformatics. DOI: 10.1093/bioinformatics/btu393.

玩朋友的丰满人妻,朋友的丰满人妻中文字幕,从后面挺进邻居丰满少妇