0

我想使用这个circlize包制作一个 RGB 配色方案。首先,我尝试制作一个函数,这样我只需要输入颜色和扇区,该函数就可以完成这项工作

这是代码:

colorpallete <- function(color, x){
    draw.sector(get.cell.meta.data("cell.start.degree", sector.index = x),
        get.cell.meta.data("cell.end.degree", sector.index = x),
        rou1 = get.cell.meta.data("cell.top.radius", track.index = 1),
        rou2 = get.cell.meta.data('cell.bottom.radius', track.index = 3),
            col = adjustcolor(col = color, alpha.f = 0.2))

    draw.sector(get.cell.meta.data("cell.start.degree", sector.index = x),
        get.cell.meta.data("cell.end.degree", sector.index = x),
        rou1 = get.cell.meta.data("cell.top.radius", track.index = 1),
        rou2 = get.cell.meta.data('cell.bottom.radius', track.index = 2),
            col = adjustcolor(col = color, alpha.f = 0.2))
            
    draw.sector(get.cell.meta.data("cell.start.degree", sector.index = x),
        get.cell.meta.data("cell.end.degree", sector.index = x),
        rou1 = get.cell.meta.data("cell.top.radius", track.index = 1),
        rou2 = get.cell.meta.data('cell.bottom.radius', track.index = 1),
            col = adjustcolor(col = color, alpha.f = 0.2))
    }

circos.initialize(sectors, xlim = c(0, 1))
        for(i in 1:3) {
            circos.track(ylim = c(0, 1))
            }
colset = (c('blue', 'cyan', 'green', 'yellow', 'red', 'violet'))
sectors = letters[1:6]    
colorpallete(colset, sectors)

当我尝试运行代码时,它返回以下错误:

 Error: Length of `sector.index` should only be 1.

如何使函数对应每个列表,例如当我调用函数时,只调用'blue'和'a',然后调用'cyan'和'b'等。

非常感谢您提前

4

1 回答 1

0

更新:我设法运行该功能:

colorpallete <- function(sectors, color){
        circos.initialize(sectors, xlim = c(0, 1))
        for(i in 1:3) {
            circos.track(ylim = c(0, 1))
            }
        for(i in 1:6){
        draw.sector(get.cell.meta.data("cell.start.degree", sector.index = sectors[i]),
            get.cell.meta.data("cell.end.degree", sector.index = sectors[i]),
            rou1 = get.cell.meta.data("cell.top.radius", track.index = 1),
            rou2 = get.cell.meta.data('cell.bottom.radius', track.index = 3),
                col = adjustcolor(col = color[i], alpha.f = 0.2))
    
        draw.sector(get.cell.meta.data("cell.start.degree", sector.index = sectors[i]),
            get.cell.meta.data("cell.end.degree", sector.index = sectors[i]),
            rou1 = get.cell.meta.data("cell.top.radius", track.index = 1),
            rou2 = get.cell.meta.data('cell.bottom.radius', track.index = 2),
                col = adjustcolor(col = color[i], alpha.f = 0.2))
                
        draw.sector(get.cell.meta.data("cell.start.degree", sector.index = sectors[i]),
            get.cell.meta.data("cell.end.degree", sector.index = sectors[i]),
            rou1 = get.cell.meta.data("cell.top.radius", track.index = 1),
            rou2 = get.cell.meta.data('cell.bottom.radius', track.index = 1),
                col = adjustcolor(col = color[i], alpha.f = 0.2))
        } circos.clear()}
sectors = letters[1:6]
colset = (c('blue', 'cyan', 'green', 'yellow', 'red', 'violet'))        
colorpallete(sectors, colset)

在此处输入图像描述

制作自定义的扇区和颜色集(不必为 6)

colorpallete <- function(sectors, color){
    if(length(sectors) != length(color)){
        print("Error: sectors should have the same length as color")
        } else {
        circos.initialize(sectors, xlim = c(0, 1))
        for(i in 1:3) {
            circos.track(ylim = c(0, 1))
            }
        for(i in 1:length(sectors)){
            draw.sector(get.cell.meta.data("cell.start.degree", sector.index = sectors[i]),
            get.cell.meta.data("cell.end.degree", sector.index = sectors[i]),
            rou1 = get.cell.meta.data("cell.top.radius", track.index = 1),
            rou2 = get.cell.meta.data('cell.bottom.radius', track.index = 3),
                col = adjustcolor(col = color[i], alpha.f = 0.2))

        draw.sector(get.cell.meta.data("cell.start.degree", sector.index = sectors[i]),
            get.cell.meta.data("cell.end.degree", sector.index = sectors[i]),
            rou1 = get.cell.meta.data("cell.top.radius", track.index = 1),
            rou2 = get.cell.meta.data('cell.bottom.radius', track.index = 2),
                col = adjustcolor(col = color[i], alpha.f = 0.2))
            
        draw.sector(get.cell.meta.data("cell.start.degree", sector.index = sectors[i]),
            get.cell.meta.data("cell.end.degree", sector.index = sectors[i]),
            rou1 = get.cell.meta.data("cell.top.radius", track.index = 1),
            rou2 = get.cell.meta.data('cell.bottom.radius', track.index = 1),
                col = adjustcolor(col = color[i], alpha.f = 0.2))
            }
    circos.clear()
    }}
sectors = letters[1:4]
colset = (c('darkblue', 'blue', 'darkred', 'red'))
colorpallete(sectors, colset)

当然,sectors而且colset需要有相同的长度

在此处输入图像描述

于 2021-07-28T04:07:24.030 回答