其他
circlize优雅的绘制多重注释弦图
图欢迎关注R语言数据分析指南
❝本节来介绍如何使用「circlize」包绘制圈图并添加外圈进行多重注释,下面通过一个小案例进行展示
❞
安装并加载R包
package.list=c("tidyverse","circlize")
for (package in package.list) {
if (!require(package,character.only=T, quietly=T)) {
install.packages(package)
library(package, character.only=T)
}
}
加载数据
df <- read_tsv("data.xls") %>% column_to_rownames(var="id") %>% as.matrix()
数据拆分
mat1 <- df[1:4,1:4]
mat2 <- df[1:4,5:8]
mat3 <- df[5:8,5:8]
mat4 <- df[5:8,9:12]
数据可视化
绘制基础图
set.seed(123)
par(bg = "white")
chordDiagram(df, annotationTrack = c("grid","axis"), directional = 1, transparency = 0,
preAllocateTracks = list( track.height = uh(4,"mm"), track.margin = c(uh(4, "mm"), 0) ))
创建轨道
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")
circos.text(mean(xlim), mean(ylim),
sector.index, col = "white", cex = 0.6, niceFacing = TRUE)})
添加外圈
highlight.sector(rownames(mat1), track.index = 1, col = "#FF8C00", text = "Chitwan",
cex = 0.8, text.col = "white", niceFacing = TRUE)
highlight.sector(colnames(mat1),track.index = 1,
col = "#1E90FF", text = "Bardia", cex = 0.8, text.col = "white", niceFacing = TRUE)
highlight.sector(colnames(mat2),track.index = 1, col = "#90EE90", text = "Khaptad",
cex = 0.8, text.col = "white", niceFacing = TRUE)
highlight.sector(colnames(mat4),track.index = 1,col = "#E41A1C",text = "Suklaphata",
cex = 0.8, text.col = "white", niceFacing = TRUE)
circos.clear()
数据获取
❝可以看到这是一个非常简单的小案例,主要想介绍如何使用「highlight.sector」函数添加外圈,喜欢的小伙伴欢迎转发此文档附上一句话到朋友圈「30分钟后台截图给我」,即可获取对应的数据及代码,如未及时回复可添加我的微信
❞
欢迎大家扫描下方二位码加入「QQ交流群」,与全国各地上千位小伙伴交流
「关注下方公众号下回更新不迷路」,如需要加入微信交流群可添加小编微信,请备注单位+方向+姓名
往期推荐