library(circlize)
circos.par(
    canvas.xlim = c(-2, 2),  # x 方向范围拉宽
    canvas.ylim = c(-1, 1),  # y 方向范围压扁
    cell.padding = c(0, 0, 0, 0),
    gap.degree = 5           # 调整染色体间距
)

# 初始化环形图
circos.initialize(
    factors = chr_length$V7,
    xlim = cbind(chr_length$V5, chr_length$V6)
)
# 绘制染色体颜色块并添加染色体名称
circos.track(
    ylim = c(0, 1),
    panel.fun = function(x, y) {
        sector_index <- CELL_META$sector.index
        circos.rect(
            CELL_META$xlim[1], 0, CELL_META$xlim[2], 1,
            col = "#C1E0DB",  # 填充颜色
            border = "white", # 边框颜色
            lwd = 3           # 增加边框宽度
        )
        circos.text(
            x = CELL_META$xcenter,
            y = 2,
            labels = sector_index,
            facing = "bending.inside",
            adj = c(0.5, 0.5),
            cex = 1
        )
    },
    track.height = 0.05  # 减小轨道高度,使图更扁平
)
circos.genomicTrackPlotRegion(gc.density, panel.fun = function(region, value, ...) {
    circos.genomicLines(region, value, col = "#F5BE8F", lwd = 2, ...)
}, track.height = 0.1,bg.border = NA)  ## bg.border = NA添加边界  track.height设置大小

circos.genomicTrackPlotRegion(gene_counts, panel.fun = function(region, value, ...) {
    circos.genomicLines(region, value, type = "h", col = "#FDDED7", lwd = 2, ...)
}, track.height = 0.1, bg.border = NA)

circos.genomicTrackPlotRegion(Sind_repeat, panel.fun = function(region, value, ...) {
    circos.genomicLines(region, value, type = "h", col = "#A28CC2", lwd = 2, ...)
}, track.height = 0.1, bg.border = NA)
circos.genomicLink(bed1, bed2, col = "#8498AB")
circos.par(
    canvas.xlim = c(-2, 2),  # x 方向范围拉宽
    canvas.ylim = c(-1, 1),  # y 方向范围压扁
    cell.padding = c(0, 0, 0, 0),
    gap.degree = 1           # 调整染色体间距
)

# 初始化环形图
circos.initialize(
    factors = chr_length2$Sind_karyotype.V3,
    xlim = cbind(chr_length2$Sind_karyotype.V5, chr_length2$Sind_karyotype.V6)
)
circos.track(
    ylim = c(0, 1),
    panel.fun = function(x, y) {
        sector_index <- CELL_META$sector.index
        circos.rect(
            CELL_META$xlim[1], 0, CELL_META$xlim[2], 1,
            col = "#C1E0DB"  # 填充颜色
            # 增加边框宽度
        )
        
    },
    track.height = 0.05  # 减小轨道高度,使图更扁平
)
circos.genomicTrackPlotRegion(gc.density, panel.fun = function(region, value, ...) {
    circos.genomicRect(region, value, col = colorRamp2(c(0.005, 0.52458, 0.69512), c("white", "pink", "red"))(value), border = NA, ...)
}, track.height = 0.1)
circos.genomicTrackPlotRegion(gene_counts2, panel.fun = function(region, value, ...) {
    circos.genomicLines(region, value, type = "h", col = "#FDDED7", lwd = 2, ...)
}, track.height = 0.1, bg.border = NA)

circos.genomicTrackPlotRegion(Sind_repeat2, panel.fun = function(region, value, ...) {
    circos.genomicRect(region, value, col = colorRamp2(c(0, 1), c("pink", "blue"))(value), border = NA, ...)
}, track.height = 0.1, bg.border = NA)
circos.genomicLink(bed1, bed2, col = "#8498AB")
circos.initialize(
  factors = chr_length$V7,
  xlim = cbind(chr_length$V5, chr_length$V6)
)

# 绘制染色体颜色块并添加染色体名称
circos.track(
    ylim = c(0, 1),
    panel.fun = function(x, y) {
        sector_index <- CELL_META$sector.index
        
        circos.rect(
            CELL_META$xlim[1], 0, CELL_META$xlim[2], 1,
            col = "#DFEFEC", border = "white"
        )
        circos.text(
            x = CELL_META$xcenter,
            y = 2.5,
            labels = sector_index,
            facing = "bending.inside",
            adj = c(0.5, 0.5),
            cex = 1
        )
    },
    track.height = 0.05  # 减小轨道高度,使图更扁平
)
circos.genomicTrackPlotRegion(gc.density, panel.fun = function(region, value, ...) {
    circos.genomicRect(region, value, col = colorRamp2(c(0.005, 0.52458, 0.69512), c("white", "#FDDED7", "red"))(value), border = NA, ...)
}, track.height = 0.1)
circos.genomicTrackPlotRegion(gene_counts, panel.fun = function(region, value, ...) {
    circos.genomicLines(region, value, type = "h", col = "#F8D6BA", lwd = 2, ...)
}, track.height = 0.05, bg.border = NA)
circos.genomicTrackPlotRegion(Sind_repeat, panel.fun = function(region, value, ...) {
    circos.genomicLines(region, value, type = "h", col = "#C5B9D9", lwd = 2, ...)
}, track.height = 0.05, bg.border = NA)