加载R包
代码语言:javascript复制library(tidyverse)
library(circlize)
library(ComplexHeatmap)
导入数据
代码语言:javascript复制df <- read_tsv("data.tsv")
数据清洗
代码语言:javascript复制mat1 <- df %>% select(-group) %>% column_to_rownames(var="sample")
df$group <- factor(df$group,levels = df$group %>% unique())
split <- df$group
定义颜色
代码语言:javascript复制col_fun1 = colorRamp2(c(-2,0,2),c("#E18727FF","white","#20854EFF"))
设置图形布局
代码语言:javascript复制circos.clear()
circos.par(canvas.xlim=c(-1,1),canvas.ylim=c(-0.5,1),
start.degree = 165,
start.degree = 0,
gap.after=c(2,2,2,200))
绘制热图
代码语言:javascript复制circos.heatmap(mat1, split = split,
col = col_fun1,
rownames.side="outside",
track.height = 0.5,
rownames.col="black",
rownames.cex=0.5,
rownames.font=1,
bg.border = "white",show.sector.labels = F)
添加文本
代码语言:javascript复制circos.track(track.index = get.current.track.index(),
panel.fun = function(x, y) {
if(CELL_META$sector.numeric.index == 4) {
cn = colnames(mat1)
n = length(cn)
circos.text(rep(CELL_META$cell.xlim[1],n) convert_x(45,"mm"),
1:n, cn, col="blACK",
cex = 0.6, adj = c(0,1),facing = "inside")
}
})
添加分组
代码语言:javascript复制circos.trackPlotRegion(ylim = c(0,0.1),track.height = 0.08,
panel.fun = function(x, y) {
chr = CELL_META$sector.index
xlim = CELL_META$xlim
ylim = CELL_META$ylim
circos.text(mean(xlim),mean(ylim),chr,cex = 1,
col = "black",facing = "outside", niceFacing = F)
})
绘制图例
代码语言:javascript复制lgd = Legend(title = "expression",col_fun = col_fun1, direction = "horizontal",
legend_width = unit(8,"cm"))
draw(lgd,x = unit(0.5,"npc"),y = unit(0.95,"npc"))
❝此图只是叠加了两层注释信息,实际分析中有更多信息的还可以继续叠加;有需要学习数据可视化的朋友,欢迎到小编的「淘宝店铺」 「R语言数据分析指南」下单购买,内容主要包括各种「高分论文的图表分析复现以及一些个性化图表的绘制」均包含数据 代码; ❞