我正在尝试使用 R 中的 circlize 包创建圆图。
这里我使用随机颜色的示例:
require(circlize)
circos.par("default.track.height" = 0.1, cell.padding = c(0, 0, 0, 0))
circos.initializeWithIdeogram(plotType = NULL)
bed1 = generateRandomBed(nr = 10)
f = colorRamp2(breaks = c(-1, 0, 1), colors = c("green", "black", "red"))
rand_col = function(k) {
return(rgb(runif(k), runif(k), runif(k)))
}
circos.genomicTrackPlotRegion(bed1, stack = FALSE, numeric.column=4, panel.fun = function(region, value, ...) {
circos.genomicRect(region, value, col = rand_col(nrow(region)), border = NA, ...)
})
会导致如下图:
现在我想传递自己的颜色 - 不是像以前那样随机生成。
bed1$clr <- sample(c("red", "green", "blue", "purple", "red",
"yellow", "blue", "red", "green", "cyan"), nrow(bed1), replace=TRUE)
circos.genomicTrackPlotRegion(bed1, stack = FALSE, numeric.column=4, panel.fun = function(region, value, ...) {
circos.genomicRect(region, value, col = bed1$clr, border = NA, ...)
})
但命中错误:
Error in .normalizeGraphicalParam(col, 1, nr, "col") :
The length of `col` (19) should be equal to 1 or the number of your regions (1).