引言
image.png
????像上面這種環(huán)形熱圖在生物信息學(xué)分析過程中被經(jīng)常用到绵估,但是通過一些軟件去繪制又比較復(fù)雜夜焦,所以,今天小編給大家介紹一下如何使用R語言中的circlize包來繪制屬于自己的環(huán)形熱圖。
正文——代碼
1激捏、前期準(zhǔn)備
1)設(shè)置工作目錄
rm(list=ls())#clear Global Environment
setwd('D:\\桌面\\環(huán)形熱圖')#設(shè)置工作路徑
2)加載包
#安裝包
if(!requireNamespace("BiocManager", quietly = T))
install.packages("BiocManager")
BiocManager::install("ComplexHeatmap")
install.packages("circlize")
#加載包
library(circlize)
library(ComplexHeatmap)
2惑惶、讀取數(shù)據(jù)
df <- read.table(file="example.txt",sep="\t",header=T,check.names=FALSE,row.names = 1)
head(df)
image.png
3煮盼、常見熱圖繪制
Heatmap(df)
image.png
4、環(huán)形熱圖繪制
1)使用circlize包中的circos.heatmap函數(shù)繪制環(huán)形熱圖带污,先查看該函數(shù)的參數(shù)
??circos.heatmap
circos.heatmap(mat, split = NULL, col, na.col = "grey",
cell.border = NA, cell.lty = 1, cell.lwd = 1,
bg.border = NA, bg.lty = par("lty"), bg.lwd = par("lwd"),
ignore.white = is.na(cell.border),
cluster = TRUE, clustering.method = "complete", distance.method = "euclidean",
dend.callback = function(dend, m, si) reorder(dend, rowMeans(m)),
dend.side = c("none", "outside", "inside"), dend.track.height = 0.1,
rownames.side = c("none", "outside", "inside"), rownames.cex = 0.5,
rownames.font = par("font"), rownames.col = "black",
show.sector.labels = FALSE, cell_width = rep(1, nrow(mat)), ...)
2)繪圖
#顏色
color <- colorRamp2(c(-5, 0, 5), c("blue", "white", "green"))
circos.par(gap.after = c(20))#間隔
circos.heatmap(df, #數(shù)據(jù)
col = color,#顏色
dend.side = "inside",#確定聚類結(jié)果放在圈內(nèi)還是圈外
rownames.side = "outside",#組名
track.height = 0.4
# clustering.method = "complete",#歸一化處理
# distance.method = "euclidean"#聚類方法僵控,默認(rèn)為歐氏距離
)
image.png
3)添加組名
circos.track(track.index = get.current.track.index(), panel.fun = function(x, y) {
if(CELL_META$sector.numeric.index == 1) {
A = length(colnames(df))
circos.text(rep(CELL_META$cell.xlim[2], A) + convert_x(0.2, "mm"), #x坐標(biāo)
28+(1:A)*10,#y坐標(biāo)
colnames(df), #標(biāo)簽
cex = 0.5, adj = c(0, 1), facing = "inside")
}
}, bg.border = NA)
##組名的標(biāo)簽位置需要耐心調(diào)整參數(shù)以到合適的位置,當(dāng)然也可以導(dǎo)出PDF在AI中進(jìn)行添加及位置調(diào)整
image.png
4)添加圖例
grid.draw(Legend(title = "Title", col_fun = color))
image.png
注意
circos.clear()#清除參數(shù)鱼冀,如果前面需要調(diào)整參數(shù)报破,必須先執(zhí)行此命令,否則繪制的新圖會(huì)和之前的圖重疊在一起
5千绪、拓展
通過該函數(shù)也可以實(shí)現(xiàn)多個(gè)熱圖的繪制:
color2=colorRamp2(c(-5, 0, 5), c("green", "white", "red"))
circos.heatmap(df, col = color, dend.side = "outside")
circos.heatmap(df, col = color2,rownames.side = "inside")
circos.clear()
image.png
參考資料:https://jokergoo.github.io/circlize_book/book/
源碼及數(shù)據(jù)在公眾號(hào)后臺(tái)回復(fù)獲瘸湟住!]┬汀盹靴!