I have created a plot similar to the one on page 8 of the circlize tutorial here: http://cran.r-project.org/web/packages/circlize/vignettes/genomic_plot.pdf
Now I am trying to overlay an additional track on top of the gene names, which shows grouping of the genes into bigger categories (in the image below taken from the vignette, I am trying to add the blue lines, hoping to get a prettier image with circlize).
I have a new data frame with the start and stop of each of these wider regions, and the labels (which I am trying to add on top of those regions).
I have tried taking the xlim, ylim, and index information from the previous plotting, but I am having trouble since it is a new data frame.
This is what I am doing: say my new dataframe (with the same coordinates as the main data) is this:
df = structure(list(Chr = c("chr1", "chr10", "chr12"), pos.start = c(2e+06, 2e+06, 2e+06), pos.end = c(3e+06, 6e+06, 3e+06), name = c("A", "B", "C")), .Names = c("Chr", "pos.start", "pos.end", "name"), row.names = c(1L, 2L, 3L), class = "data.frame")
After initialising the circos using my primary dataset and it's factors for genes as in the example vignette, I am trying to add the track like this:
circos.trackPlotRegion(ylim = c(0.5, 0.5), track.index=1,
panel.fun = function(x, y) {
chr = get.cell.meta.data("sector.index")
# find regions in this chromosome
regions = unique(df[df$Chr == chr, , drop = FALSE]$name)
df2 = df[df$Chr == chr, , drop = FALSE]
for(i in seq_len(nrow(df2))) {
region = which(regions %in% df2$name[i])
circos.rect(region, 0.2,
region, 0.2, color="blue", border = NA)
}
}, bg.border = NA)
And I keep getting this error: "Error in if (ncut) { : argument is not interpretable as logical".
What am I doing wrong?
I also tried overlaying a whole new plot using par(new = TRUE), but I can't get it to overlap exactly to my previous plot since it rescales to fit the whole circle (while I only have some segments defined for the wider regions). If anybody has pointers on how to draw this overlaying region (using a different dataset defining these wider regions) in circlize in R I would very much appreciate it!
Thank you for the help!