导读
堆叠图或pheatmap图的另一种展现形式----和弦图。这里用的是矩阵数据melt成含对应关系的三列表,有对应关系即可,是非矩阵都可以。另外circos函数博大精深,很值得学习哦。
一、模拟输入
library(circlize)
library(reshape2)
data = data.frame(matrix(sample(100, 16, replace=F), 4, 4))
rownames(data) = paste("sample", 1:4, sep=".")
colnames(data) = paste("bacteria", 1:4, sep=".")

data = data.frame(data, taxonomy = rownames(data))

input = melt(data, id='taxonomy')

二、和弦图
pdf("circ.pdf")
chordDiagram(input)
dev.off()

三、自定义顺序
倒序
queue = c(paste("sample", c(4,3,2,1), sep="."), paste("bacteria", c(4,3,2,1), sep="."))
pdf("circ_order.pdf")
chordDiagram(input, order = queue)
dev.off()

四、自定义颜色
1 连线颜色
pdf("circ_line_color.pdf")
chordDiagram(input, col = c("red", "skyblue", "pink", "yellow"))
dev.off()

2 标签颜色
pdf("circ_label_color.pdf")
chordDiagram(input, grid.col = c(sample.1="red", sample.2="skyblue", sample.3="pink", sample.4="yellow", bacteria.1="purple", bacteria.2="green", bacteria.3="grey", bacteria.4="orange"))
dev.off()

五、选择展示标签、刻度、方格
1 去标签
pdf("circ_no_name.pdf")
chordDiagram(input, annotationTrack = c("axis", "grid"), grid.col = c(sample.1="red", sample.2="skyblue", sample.3="pink", sample.4="yellow", bacteria.1="purple", bacteria.2="green", bacteria.3="grey", bacteria.4="orange"))
dev.off()

2 去刻度
pdf("circ_no_axis.pdf")
chordDiagram(input, annotationTrack = c("name", "grid"), grid.col = c(sample.1="red", sample.2="skyblue", sample.3="pink", sample.4="yellow", bacteria.1="purple", bacteria.2="green", bacteria.3="grey", bacteria.4="orange"))
dev.off()

3 去方格
刻度一起没了
pdf("circ_no_grid.pdf")
chordDiagram(input, annotationTrack = c("name", "axis"), grid.col = c(sample.1="red", sample.2="skyblue", sample.3="pink", sample.4="yellow", bacteria.1="purple", bacteria.2="green", bacteria.3="grey", bacteria.4="orange"))
dev.off()

更多参数:
small.gap = 0.001 # 组内空隙,默认是两个组
big.gap = 1 # 组建空隙
order = c() # 自定义label的顺序
label = c(paste("u", 1:73, sep="."),
paste("c", 1:50, sep="."), "unco_c", "unco_u")
col_set = c(rep("red", 73), rep("blue", 50), "grey", "grey")
names(col_set) = label
grid.col = col_set # 自定义配色
比较基因组数据结构:

随便画:

参考:
和弦图绘制
R语言circlize包总结
R包circlize绘制弦状图示例
The chordDiagram() function
R circlize circos book
网友评论