用R语言的circlize包复现一下Microbiome期刊中的圈图

论文

Heritability and recursive influence of host genetics on the rumen microbiota drive body weight variance in male Hu sheep lambs
复现论文中的fig2

image.png
没有找到论文中提供的数据,我们自己来构造数据,如何利用otu表格把数据整理成作图需要用的格式,这个今天的推文不做介绍,今天的推文只介绍已经有了作图需要用到的数据后如何作图。
(others phylum 这个英文表述是不是有问题?有没有大佬可以解释一下?)
首先是最外圈的数据

image.png
最外圈文字的数据

image.png
第二圈数据

image.png
第三圈的数据

与第二圈的数据格式一致
第四圈的数据

image.png
第五圈的数据

利用第三圈的数据生成
最里层连线的数据

image.png
完整的代码

library(circlize)
library(readxl)
library(tidyverse)
library(“RColorBrewer”)

dat01<-read_excel(“2024.data/20240610/data01.xlsx”) dat01 %>%
mutate(phylum=factor(phylum,levels = phylum)) -> dat01

dat02<-read_excel(“2024.data/20240610/data02.xlsx”)
dat02

dat03<-read_excel(“2024.data/20240610/data03.xlsx”)
dat03

dat04<-read_excel(“2024.data/20240610/data04.xlsx”)
dat04

dat05<-read_excel(“2024.data/20240610/data05.xlsx”)
dat05

dat06.mat<-dat03 %>% pull(y) %>% as.matrix(ncol=1)
dat06.mat

data07<-read_excel(“2024.data/20240610/data07.xlsx”)
data07

brk<-seq(0,30,2)
brk
circos.par(start.degree =86,clock.wise = T)

热图的圈参考链接 https://jokergoo.github.io/circlize_book/book/circos-heatmap.html

circos.heatmap.initialize(dat06.mat,
split = factor(dat06$phylum,
levels = dat06$phylum %>% unique()))
circos.initialize(factors = dat01$phylum,
xlim = matrix(c(dat01$start,dat01$numberofgenera),ncol=2))

第一圈文字

circos.genomicLabels(dat02,side = “outside”,labels.column = 4)

第一圈灰色背景

circos.trackPlotRegion(dat01$phylum,
ylim = c(0, 10),
track.height = 0.05,
bg.border = NA,
#ylim=CELL_META$ylim,
panel.fun = function(x, y) {
circos.text(mean(CELL_META$xlim),mean(CELL_META$ylim),
get.cell.meta.data(“sector.index”))
},
bg.col=’#EEEEEE6E’)

第一圈线段

for (chromosome in dat02$phylum){
circos.segments(sector.index = chromosome,
x0=dat02[dat02$phylum==chromosome,]$start,
x1=dat02[dat02$phylum==chromosome,]$end,
y0=-2,y1=12,col=”red”)
}

第一圈刻度

for (chromosome in dat01$phylum){
circos.axis(sector.index = chromosome,
h = 12,
major.at = brk,
minor.ticks = 0,
labels = FALSE)
}

第二圈

circos.trackPlotRegion(dat01$phylum,
ylim = c(0, 100),
track.height = 0.1,
bg.col = ‘#EEEEEE6E’,
bg.border = “black”)

for (chromosome in dat03$phylum){
circos.points(sector.index = chromosome,
x=dat03[dat03$phylum==chromosome,]$x,
y=dat03[dat03$phylum==chromosome,]$y,
col=”red”,
pch=19)
}

第三圈

circos.trackPlotRegion(dat01$phylum,
ylim = c(0, 100),
track.height = 0.1,
bg.col = ‘#EEEEEE6E’,
bg.border = NA)

for (chromosome in dat04$phylum){
circos.lines(sector.index = chromosome,
x=dat04[dat04$phylum==chromosome,]$x,
y=dat04[dat04$phylum==chromosome,]$y,
col=”#559a90″,
area=TRUE,
border=NA,
type=”I”)

}

第四圈

circos.trackPlotRegion(dat01$phylum,
ylim = c(0, 100),
track.height = 0.05,
bg.col = ‘#EEEEEE6E’,
bg.border = “black”)

for (chromosome in dat05$phylum){
circos.points(sector.index = chromosome,
x=dat05[dat05$phylum==chromosome,]$x,
y=dat05[dat05$phylum==chromosome,]$y,
col=”red”,
pch=dat05[dat05$phylum==chromosome,]$shape)
}

第五圈

circos.heatmap(dat06.mat,
col = colorRamp2(breaks = c(0, 50, 100),
col = brewer.pal(n = 3, name = “RdBu”)),
track.height=0.1)

最内圈的连线

for (i in 1:nrow(data07)){
circos.link(sector.index1=data07$phylum01[i],
point1=data07$x01[i],
sector.index2=data07$phylum02[i],
point2=data07$x02[i])
}

circos.clear()

出图结果
图例的部分可能需要借助AI来拼图了
今天推文的示例数据和代码可以给推文打赏20元获取
欢迎大家关注我的公众号
小明的数据分析笔记本

声明:文中观点不代表本站立场。本文传送门:https://eyangzhen.com/417255.html

(0)
联系我们
联系我们
分享本页
返回顶部