jokergoo / circlize

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

question: customize circos.genomicInitialize() #79

Closed phiweger closed 6 years ago

phiweger commented 6 years ago

Hi,

How can one change the default plotting properties of circos.genomicInitialize()?

Specifically, how could I for example

Thank you!

jokergoo commented 6 years ago

To change the fontsize, you can set it globally by par(cex = ...).

The chromosome name and the axes are added by circos.text() and circos.axis() internally by cirocs.genomicInitialize(). If you set plotType = NULL in the function, later you can add the chromosome names as well as the axes by hand.

circos.genomicInitialize(..., plotType = NULL)
# add a track for the chromosome name and axes
circos.track(..., panel.fun = function(x, y) {
    circos.text(CELL_META$xcenter, CELL_META$ycenter, CELL_META$sector.index)
    circos.axis(h = "bottom", at = ..., label = ...)  # you can change "bp" to "nt" by setting label
}
...
RaverJay commented 5 years ago

Adding the axis by hand defeats the purpose of using circos.genomicInitialize()

I would suggest adding a parameter to it (and circos.genomicAxis) that lets the user decide the tick label suffix, as 'bp' is not fitting for all single stranded genomics applications.

As a workaround for anyone searching this, running this: fixInNamespace('circos.genomicAxis', 'circlize') lets you change the code of the function to do what you want.

Cheers

jokergoo commented 5 years ago

Axes contain too many graphic elements that it will make the function arguments like a monster if considering to support all graphic parameters, but I will try to support those general graphic parameters as much as possible.

jokergoo commented 5 years ago

I just updated the package. In this new version, for circos.genomicAxis(), I added two arguments major.at and labels that you can use to control the breaks and the corresponding labels. For controlling the font size of the axes labels, there was already a labels.cex in the function.

par(mfrow = c(2, 2))

circos.initializeWithIdeogram(plotType = NULL)
circos.track(ylim = c(0, 1), panel.fun = function(x, y) {
    circos.genomicAxis(labels.cex = 0.4)
})
circos.clear()

circos.initializeWithIdeogram(plotType = NULL)
circos.track(ylim = c(0, 1), panel.fun = function(x, y) {
    circos.genomicAxis(major.at = seq(0, 1e10, by = 1e8), labels.cex = 0.4)
})
circos.clear()

circos.initializeWithIdeogram(plotType = NULL)
circos.track(ylim = c(0, 1), panel.fun = function(x, y) {
    breaks = seq(0, 1e10, by = 1e8)
    circos.genomicAxis(major.at = breaks, labels = paste0(breaks/1e9, "GB"), labels.cex = 0.4)
})
circos.clear()

image

When you manually set the breaks for axes, because chromosomes are with different length, you don;t need to set breaks for each chromosome according to the current chromosome length, while you can set with a very long chromosome that is longer than all chromosomes, e.g. breaks = seq(0, 1e10, by = 1e8) in the example code, the breaks values are automatically clipped for each chromosome.