I am trying create circle diagram using circlize package in R.
Here example where I use random color:
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, ...)
})
Will lead to figure like this:

Now I would like to pass own colors - not random as generated in previous case.
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, ...)
})
But hit error:
Error in .normalizeGraphicalParam(col, 1, nr, "col") :
The length of `col` (19) should be equal to 1 or the number of your regions (1).
in
panel.fun,regionandvaluecorrespond to the data on each chromosome, so you cannot usebed1$clrbecausebed1$clrcorresponds to the whole data.actually, in
panel.fun,valuecontains columns excluding the first three columns inbed1and only contains data for the current chromosome (rememberpanel.funapplied on each chromosome), so you can change your code to:BTW, replace
default.track.heighttotrack.heightincircos.parif you are using the latest version ofcirclize(0.1.3).