## circos plot
### 应用场景
展示各组数据之间所占比例
>创建一个实例数据结构如下
![data format](http://kancloud.nordata.cn/2018-12-30-074325.png)
```R
# 读取数据
load('./test_cir.Rdata') #rt_cir
load('./color_list.Rdata') #color_list
# 定义各个组的颜色
state_col <- color_list[3:25]
names(state_col) <- c(colnames(rt_cir), row.names(rt_cir))
state_col2 <- state_col[4:23]
colmat <- rep(state_col2, 3)
dim(colmat) <- dim(rt_cir)
```
>作图
```R
# 简单的展示各个组别的数量大小和比例
circos.par(start.degree = 90, clock.wise = FALSE)
cdm_res = chordDiagram(rt_cir, col = colmat, grid.col = state_col, directional = FALSE,
annotationTrack = "grid", preAllocateTracks = list(track.height = 0.5))
```
![cir1](http://kancloud.nordata.cn/2018-12-30-074332.png)
```R
# 为各个组别加上刻度标签
circos.par(start.degree = 90, clock.wise = FALSE)
cdm_res = chordDiagram(rt_cir, col = colmat, grid.col = state_col, directional = FALSE,
annotationTrack = "grid", preAllocateTracks = list(track.height = 0.5))
# 为各个组别刻度标签
circos.track(track.index = 2, panel.fun = function(x, y) {
sector.index = get.cell.meta.data("sector.index")
xlim = get.cell.meta.data("xlim")
ylim = get.cell.meta.data("ylim")
xlim = CELL_META$xlim
breaks = seq(0, xlim[2], by = 5e4)
circos.axis(major.at = breaks, labels = paste0(breaks/2000, "KB"), labels.cex = 0.5, minor.ticks = 1, labels.facing = "reverse.clockwise")
}, bg.border = NA)
```
![cir2](http://kancloud.nordata.cn/2018-12-30-074335.png)
```R
# 加上一个比例刻度和组名
circos.par(start.degree = 90, clock.wise = FALSE)
cdm_res = chordDiagram(rt_cir, col = colmat, grid.col = state_col, directional = FALSE,
annotationTrack = "grid", preAllocateTracks = list(track.height = 0.5))
### 为各个组别刻度标签
for(si in get.all.sector.index()) {
circos.axis(h = "top", labels.cex = 0.3, sector.index = si, track.index = 2)
}
# the second axis as well as the sector labels are added in this track
circos.track(track.index = 1, panel.fun = function(x, y) {
xlim = get.cell.meta.data("xlim")
ylim = get.cell.meta.data("ylim")
sector.name = get.cell.meta.data("sector.index")
xplot = get.cell.meta.data("xplot")
circos.lines(xlim, c(mean(ylim), mean(ylim)), lty = 3) # dotted line
by = ifelse(abs(xplot[2] - xplot[1]) > 30, 0.2, 0.5)
for(p in seq(by, 1, by = by)) {
circos.text(p*(xlim[2] - xlim[1]) + xlim[1], mean(ylim) + 0.1,
paste0(p*100, "%"), cex = 0.3, adj = c(0.5, 0), niceFacing = TRUE)
}
circos.text(mean(xlim), 1, sector.name, niceFacing = TRUE, adj = c(0.5, 0))
}, bg.border = NA)
circos.clear()
```
![cir3](http://kancloud.nordata.cn/2018-12-30-074336.png)
```R
# 为使图片看起来更加饱满,外围再重复叠加组别比列图
circos.par(start.degree = 90, clock.wise = FALSE)
cdm_res = chordDiagram(rt_cir, col = colmat, grid.col = state_col, directional = FALSE,
annotationTrack = "grid", preAllocateTracks = list(track.height = 0.5))
for(i in seq_len(nrow(cdm_res))) {
if(cdm_res$value[i] > 0) {
circos.rect(cdm_res[i, "x1"], -uy(3.5, "mm"),
cdm_res[i, "x1"] - abs(cdm_res[i, "value"]), -uy(2.5, "mm"),
col = state_col[cdm_res$cn[i]], border = state_col[cdm_res$cn[i]], sector.index = cdm_res$rn[i], track.index = 2)
circos.rect(cdm_res[i, "x2"], -uy(3.5, "mm"),
cdm_res[i, "x2"] - abs(cdm_res[i, "value"]), -uy(2.5, "mm"),
col = state_col[cdm_res$rn[i]], border = state_col[cdm_res$rn[i]], sector.index = cdm_res$cn[i], track.index = 2)
circos.rect(cdm_res[i, "x1"], -uy(-0.75, "mm"),
cdm_res[i, "x1"] - abs(cdm_res[i, "value"]), -uy(-0.85, "mm"),
col = state_col[cdm_res$cn[i]], border = state_col[cdm_res$cn[i]], sector.index = cdm_res$rn[i], track.index = 1)
circos.rect(cdm_res[i, "x2"], -uy(-0.75, "mm"),
cdm_res[i, "x2"] - abs(cdm_res[i, "value"]), -uy(-0.85, "mm"),
col = state_col[cdm_res$rn[i]], border = state_col[cdm_res$rn[i]], sector.index = cdm_res$cn[i], track.index = 1)
circos.rect(cdm_res[i, "x1"], -uy(-0.95, "mm"),
cdm_res[i, "x1"] - abs(cdm_res[i, "value"]), -uy(-1.15, "mm"),
col = state_col[cdm_res$rn[i]], border = state_col[cdm_res$rn[i]], sector.index = cdm_res$rn[i], track.index = 1)
circos.rect(cdm_res[i, "x2"], -uy(-0.95, "mm"),
cdm_res[i, "x2"] - abs(cdm_res[i, "value"]), -uy(-1.15, "mm"),
col = state_col[cdm_res$cn[i]], border = state_col[cdm_res$cn[i]], sector.index = cdm_res$cn[i], track.index = 1)
}
}
circos.track(track.index = 2, panel.fun = function(x, y) {
sector.index = get.cell.meta.data("sector.index")
xlim = get.cell.meta.data("xlim")
ylim = get.cell.meta.data("ylim")
xlim = CELL_META$xlim
breaks = seq(0, xlim[2], by = 5e4)
circos.axis(major.at = breaks, labels = paste0(breaks/2000, "KB"), labels.cex = 0.5, minor.ticks = 1, labels.facing = "reverse.clockwise")
}, bg.border = NA)
circos.track(track.index = 1, panel.fun = function(x, y) {
sector.index = get.cell.meta.data("sector.index")
xlim = get.cell.meta.data("xlim")
ylim = get.cell.meta.data("ylim")
circos.text(mean(xlim), 0.82, sector.index, cex = 0.7, facing = "reverse.clockwise", niceFacing = TRUE)
xlim = CELL_META$xlim
sector.name = get.cell.meta.data("sector.index")
xplot = get.cell.meta.data("xplot")
circos.lines(xlim, c(mean(ylim)/2.04, mean(ylim)/2.04), lty = 3) # dotted line
by = ifelse(abs(xplot[2] - xplot[1]) > 30, 0.2, 0.5)
for(p in seq(by, 1, by = by)) {
circos.text(p*(xlim[2] - xlim[1]) + xlim[1], mean(ylim)/2.5,
paste0(p*100, "%"), cex = 0.4, adj = c(0.5, 0), niceFacing = TRUE, facing = "reverse.clockwise")
}
}, bg.border = NA)
circos.clear()
```
![cir4](http://kancloud.nordata.cn/2018-12-30-074337.png)
- 智汇医圈
- 第一章 前言
- 1.1 简介
- 1.2 制作该教程的目的
- 1.3 学习该教程需要掌握的基础知识
- 1.4 该教程适用人群
- 第二章 散点图(scatter plot)
- 2.1 基本的散点图
- 2.2 3D 散点图
- 第三章 线图(line plot)
- 3.1 基本的线图
- 第四章 箱型图(boxplot)
- 4.1 基本的箱型图
- 4.2 图形参数调整
- 4.3 多分组箱型图
- 4.4 小提琴图
- 第五章 密度图(density plot)
- 5.1 基本的密度图
- 第六章 热图(Heatmap)
- 6.1 基本的热图
- 6.2 ggplot2 heatmap
- 6.3 相关性热图
- 第七章 主成分分析(PCA)
- 7.1 2D PCA
- 7.2 3D PCA
- 第八章 ROC 曲线
- 8.1 基本的 ROC 曲线
- 第九章 生存分析(KM plot)
- 9.1 基本的生存分析
- 第十章 KEGG 和 GO 分析
- 10.1 KEGG 分析
- 10.2 GO 分析
- 第十一章 Circular plot
- 11.1 基本的 Circular plot
- 附录 下载数据