jokergoo / circlize

Circular visualization in R
http://jokergoo.github.io/circlize_book/book/
Other
963 stars 145 forks source link

Adding background lines to genomicDensity() #364

Closed elcortegano closed 1 year ago

elcortegano commented 1 year ago

Hi, I'm having difficulties finding a way to plot a track with genomicDensity that shows also shows background lines to easy the comparison of density across chromosomes.

The following instruction works for me, but does not add tracks:

circos.genomicDensity(mybed, col = "black",  track.height = 0.01) 

However, if embed this code within a genomicTrack call that creates background lines, I get a mysterious error "Your data frame is less than 3 column!". Not sure why. This is the code:

circos.genomicTrack(mybed, ylim=c(0,1),
                panel.fun = function(region, value, ...) {
                    for(h in seq(0, 1, by = 0.2)) {
                        circos.lines(CELL_META$cell.xlim, c(h, h), lty = 3, col = "grey")
                    }
                    circos.genomicDensity(region, value, col = "black")
                }, track.height = 0.1)

Any ideas on what is going wrong? thank you!

jokergoo commented 1 year ago

It is because circos.genomicDensity() is a "high-level" function which creates a new track.

This track is basically drawn by the function circos.genomicLines(). You can check the following code:


circos.initializeWithIdeogram(plotType = c("axis", "labels"))
gr = genomicDensity(DMR_hyper)

ymax = max(gr[, 4])

circos.genomicTrackPlotRegion(gr, ylim = c(0, ymax),
    panel.fun = function(region, value, ...) {
        for(i in 1:3) {
            circos.lines(CELL_META$cell.xlim, rep(ymax/4*i, 2), lty = 2, col = "#AAAAAA")
        }
        circos.genomicLines(region, value, col = "#FF000080", border = NA, area = TRUE, baseline = 0)
    })
circos.clear()
image
elcortegano commented 1 year ago

It works like a charm!, beautiful design, thank you!