前些天在网上看到的代码,他最终的出图如下
image.png
这份教程的链接地址是 https://www.royfrancis.com/beautiful-circos-plots-in-r/
但是他没有公布完整的数据,只是提到了数据的格式,我试着按照他提到的数据自己模拟了一份数据
因为只有三条染色体,数据不多,直接通过代码输入
circos.initialize(factors=c("genome_1","genome_2","genome_3"),
xlim=matrix(c(0,0,0,100,120,110),ncol=2))
image.png
image.png
image.png
image.png
image.png
教程中提到了两套代码,一套是不带参数调整细节
完整代码如下
'''
### 弦图
### 参考链接
### https://www.royfrancis.com/beautiful-circos-plots-in-r/
'''
library(readxl)
cov<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet1")
cov
gc<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet2")
gc
ann<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet3")
ann
nuc1<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet4")
nuc1
nuc2<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet5")
nuc2
library(circlize)
col_text <- "grey40"
#circos.par("track.height"=0.8,gap.degree=5,cell.padding=c(0,0,0,0))
circos.initialize(factors=c("genome_1","genome_2","genome_3"),
xlim=matrix(c(0,0,0,100,120,110),ncol=2))
circos.track(ylim=c(0,1),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)
})
circos.track(track.index = get.current.track.index(),
panel.fun = function(x, y) {
circos.axis(h="top")
})
circos.genomicTrack(data=cov,
panel.fun=function(region,value,...) {
circos.genomicLines(region,value)
})
# coverage y axis
circos.yaxis()
circos.track(factors=gc$chr,
x=gc$start,
y=gc$value1,
panel.fun=function(x,y) {
circos.lines(x,y)
})
# gc y axis
circos.yaxis()
circos.genomicLabels(ann,labels.column=5)
circos.genomicLink(nuc1,nuc2)
circos.clear()
出图
image.png
'''
### 弦图
### 参考链接
### https://www.royfrancis.com/beautiful-circos-plots-in-r/
'''
library(readxl)
cov<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet1")
cov
gc<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet2")
gc
ann<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet3")
ann
nuc1<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet4")
nuc1
nuc2<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet5")
nuc2
library(circlize)
col_text <- "grey40"
circos.par("track.height"=0.8,gap.degree=5,cell.padding=c(0,0,0,0))
circos.initialize(factors=c("genome_1","genome_2","genome_3"),
xlim=matrix(c(0,0,0,100,120,110),ncol=2))
circos.track(ylim=c(0,1),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=0.5,col=col_text,
facing="bending.inside",niceFacing=TRUE)
},bg.col="grey90",bg.border=F,track.height=0.06)
brk <- c(0,20,40,60,80,100,120)
circos.track(track.index = get.current.track.index(),
panel.fun = function(x, y) {
circos.axis(h="top",
major.at=brk,
labels=brk,
labels.cex=0.4,
col=col_text,
labels.col=col_text,
lwd=0.7,
labels.facing="clockwise")
},
bg.border=F)
circos.genomicTrack(data=cov,
panel.fun=function(region,value,...) {
circos.genomicLines(region,
value,
type="l",
col="grey50",
lwd=0.6)
circos.segments(x0=0,
x1=120,
y0=100,
y1=100,
lwd=0.6,
lty="11",
col="grey90")
circos.segments(x0=0,
x1=120,
y0=150,
y1=150,
lwd=0.6,
lty="11",
col="grey90")
#circos.segments(x0=0,x1=max(ref$V2),y0=500,y1=500,lwd=0.6,lty="11",col="grey90")
},
track.height=0.08,
bg.border=F)
circos.yaxis(at=c(100,150),
labels.cex=0.25,
lwd=0,
tick.length=0,
labels.col=col_text,
col="#FFFFFF")
circos.track(factors=gc$chr,
x=gc$start,
y=gc$value1,
panel.fun=function(x,y) {
circos.lines(x,y,col="grey50",lwd=0.6)
circos.segments(x0=0,
x1=120,
y0=30,
y1=30,
lwd=0.6,
lty="11",
col="grey90")
circos.segments(x0=0,
x1=120,
y0=50,
y1=50,
lwd=0.6,
lty="11",
col="grey90")
circos.segments(x0=0,
x1=150,
y0=70,
y1=70,
lwd=0.6,
lty="11",
col="grey90")
},
ylim=c(30,70),
track.height=0.08,
bg.border=F)
# gc y axis
circos.yaxis(at=c(30,50,70),
labels.cex=0.25,
lwd=0,
tick.length=0,
labels.col=col_text,
col="#FFFFFF")
circos.genomicLabels(ann,
labels.column=5,
cex=0.25,
col=col_text,
line_lwd=0.5,
line_col="grey80",
side="inside",
connection_height=0.05,
labels_height=0.04)
rcols <- scales::alpha(ifelse(sign(nuc1$start-nuc1$end)!=sign(nuc2$start-nuc2$end),"#f46d43","#66c2a5"),alpha=0.4)
rcols
circos.genomicLink(nuc1,nuc2,col=rcols,border=NA)
circos.clear()
image.png
这个表示覆盖度和gc含量的折线数据比较少,看起来可能不太美观,换成自己的数据多了以后就好看了
示例数据和代码可以直接在公众号后台留言 20210617
获取
欢迎大家关注我的公众号
小明的数据分析笔记本
小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!