天天看点

R语言circlize包实例3

根据vcf文件计算SNP密度并用circlize可视化结果

在这篇文章中遇到的问题是我想开个口子用来添加文字标签,暂时还不知道如何实现

在 https://www.promptcloud.com/blog/data-visualization-text-mining-taylor-swift-song-lyrics/ 这篇文章里找到了答案

可以通过

circos.par(gap.after())

来实现

例子

不开口

df<-read.table("SNPdensity.snpden",sep="\t",header=T)
head(df)
df<-df[,c(1,2,4)]
colnames(df)<-c("Chr","X","Y")
head(df)
df$X<-df$X/1000000
options(scipen=999)
library(circlize)
library(RColorBrewer)
col<-RColorBrewer::brewer.pal(8,"Paired")
circos.par(gap.after=c(2,2,2,2,4,4,4,30),"start.degree" = 90)
circos.initialize(factors=df$Chr,x=df$X)
circos.trackPlotRegion(factors=df$Chr,y=df$Y,
                       panel.fun=function(x,y){
                         circos.axis()
                       },track.height = 0.05)

for(i in 1:8){
  highlight.sector(sector.index = paste0("LG",i),col=col[i])
  circos.text(CELL_META$xcenter, CELL_META$ycenter,
              labels = paste0("LG",i),
              sector.index = paste0("LG",i),cex=0.5)
}
circos.trackPlotRegion(factors=df$Chr,y=df$Y)
circos.trackLines(df$Chr,df$X,df$Y,col=col)
circos.clear()
           

复制

R语言circlize包实例3

image.png

开口

circos.par(gap.after=c(2,2,2,2,2,2,2,30),"start.degree" = 90)
circos.initialize(factors=df$Chr,x=df$X)
circos.trackPlotRegion(factors=df$Chr,y=df$Y,
                       panel.fun=function(x,y){
                         circos.axis()
                       },track.height = 0.05)

for(i in 1:8){
  highlight.sector(sector.index = paste0("LG",i),col=col[i])
  circos.text(CELL_META$xcenter, CELL_META$ycenter,
              labels = paste0("LG",i),
              sector.index = paste0("LG",i),cex=0.5)
}
circos.trackPlotRegion(factors=df$Chr,y=df$Y)
circos.trackLines(df$Chr,df$X,df$Y,col=col)
circos.clear()
           

复制

R语言circlize包实例3

image.png

实现开口用到的函数是

circos.par(gap.after=c(2,2,2,2,2,2,2,30),"start.degree" = 90)

在开口处添加文字

circos.par(gap.after=c(2,2,2,2,2,2,2,30),"start.degree" = 75)
circos.initialize(factors=df$Chr,x=df$X)
circos.trackPlotRegion(factors=df$Chr,y=df$Y,
                       panel.fun=function(x,y){
                         circos.axis()
                       },track.height = 0.05)

for(i in 1:8){
  highlight.sector(sector.index = paste0("LG",i),col=col[i])
  circos.text(CELL_META$xcenter, CELL_META$ycenter,
              labels = paste0("LG",i),
              sector.index = paste0("LG",i),cex=0.5)
}
circos.text(x=-11,y=8,labels="染色体",sector.index = "LG1")
circos.trackPlotRegion(factors=df$Chr,y=df$Y)
circos.trackLines(df$Chr,df$X,df$Y,col=col)
circos.text(x=-10,y=11,labels="SNP密度",sector.index = "LG1")
circos.clear()
           

复制

R语言circlize包实例3