### Example: Plotting with absolute units for track height and line length Source: https://github.com/jokergoo/circlize_book/blob/master/book/circular-layout.html This example demonstrates setting track heights using mm_h(), cm_h(), and inch_h(), and drawing lines with lengths defined by mm_x(), cm_x(), and cm_y(). ```R sectors = letters[1:10] circos.par(cell.padding = c(0, 0, 0, 0), track.margin = c(0, 0)) circos.initialize(sectors, xlim = cbind(rep(0, 10), runif(10, 0.5, 1.5))) circos.track(ylim = c(0, 1), track.height = mm_h(5), panel.fun = function(x, y) { circos.lines(c(0, 0 + mm_x(5)), c(0.5, 0.5), col = "blue") }) circos.track(ylim = c(0, 1), track.height = cm_h(1), track.margin = c(0, mm_h(2)), panel.fun = function(x, y) { xcenter = get.cell.meta.data("xcenter") circos.lines(c(xcenter, xcenter), c(0, cm_y(1)), col = "red") }) circos.track(ylim = c(0, 1), track.height = inch_h(1), track.margin = c(0, mm_h(5)), panel.fun = function(x, y) { line_length_on_x = cm_x(1*sqrt(2)/2) line_length_on_y = cm_y(1*sqrt(2)/2) circos.lines(c(0, line_length_on_x), c(0, line_length_on_y), col = "orange") }) circos.clear() ``` -------------------------------- ### Set start.degree parameter Source: https://github.com/jokergoo/circlize_book/blob/master/book/02-circlize-layout.md Use `circos.par()` to set a specific graphic parameter before initializing the circular layout. This example sets the starting degree to 30. ```r circos.par("start.degree" = 30) ``` -------------------------------- ### Example of setting absolute units in tracks Source: https://github.com/jokergoo/circlize_book/blob/master/book/02-circlize-layout.md Demonstrates using mm_h(), cm_h(), inch_h(), mm_x(), cm_x(), and cm_y() to define track heights, line lengths, and margins with absolute units. ```r sectors = letters[1:10] circos.par(cell.padding = c(0, 0, 0, 0), track.margin = c(0, 0)) circos.initialize(sectors, xlim = cbind(rep(0, 10), runif(10, 0.5, 1.5))) circos.track(ylim = c(0, 1), track.height = mm_h(5), panel.fun = function(x, y) { circos.lines(c(0, 0 + mm_x(5)), c(0.5, 0.5), col = "blue") }) circos.track(ylim = c(0, 1), track.height = cm_h(1), track.margin = c(0, mm_h(2)), panel.fun = function(x, y) { xcenter = get.cell.meta.data("xcenter") circos.lines(c(xcenter, xcenter), c(0, cm_y(1)), col = "red") }) circos.track(ylim = c(0, 1), track.height = inch_h(1), track.margin = c(0, mm_h(5)), panel.fun = function(x, y) { line_length_on_x = cm_x(1*sqrt(2)/2) line_length_on_y = cm_y(1*sqrt(2)/2) circos.lines(c(0, line_length_on_x), c(0, line_length_on_y), col = "orange") }) ``` ```r circos.clear() ``` -------------------------------- ### Basic Chord Diagram with Matrix Source: https://github.com/jokergoo/circlize_book/blob/master/book/14-chord-diagram-simple.md Use this snippet to generate a basic chord diagram directly from a matrix. Ensure the circlize package is installed and loaded. ```r chordDiagram(mat) ``` ```r circos.clear() ``` -------------------------------- ### Chord Diagram with Negative DiffHeight and Arrows Source: https://github.com/jokergoo/circlize_book/blob/master/book/the-chorddiagram-function.html Demonstrates setting `diffHeight` to a negative value, resulting in longer start ends for links, in conjunction with arrows for direction. ```R chordDiagram(matx, directional = 1, direction.type = c("diffHeight", "arrows"), ``` -------------------------------- ### General draw.sector() usage Source: https://github.com/jokergoo/circlize_book/blob/master/book/03-graphics.md Demonstrates various ways to draw sectors using `draw.sector()`. Specify start and end degrees, radii, center, and appearance properties like color and border. ```r draw.sector(start.degree, end.degree, rou1) draw.sector(start.degree, end.degree, rou1, rou2, center) draw.sector(start.degree, end.degree, rou1, rou2, center, col, border, lwd, lty) ``` ```r draw.sector(start.degree, end.degree, clock.wise = FALSE) ``` ```r par(mar = c(1, 1, 1, 1)) plot(c(-1, 1), c(-1, 1), type = "n", axes = FALSE, ann = FALSE, asp = 1) draw.sector(20, 0) draw.sector(30, 60, rou1 = 0.8, rou2 = 0.5, clock.wise = FALSE, col = "#FF000080") draw.sector(350, 1000, col = "#00FF0080", border = NA) draw.sector(0, 180, rou1 = 0.25, center = c(-0.5, 0.5), border = 2, lwd = 2, lty = 2) draw.sector(0, 360, rou1 = 0.7, rou2 = 0.6, col = "#0000FF80") ``` -------------------------------- ### WGBS DMR Visualization Setup Source: https://github.com/jokergoo/circlize_book/blob/master/book/nested-zooming.html Initializes a circular plot with ideograms for chromosomes and then sets up a genomic track for visualizing DMR data. Includes helper lines for reference. ```R chr_bg_color = rand_color(22, transparency = 0.8) names(chr_bg_color) = paste0("chr", 1:22) f1 = function() { circos.par(gap.after = 2, start.degree = 90) circos.initializeWithIdeogram(chromosome.index = paste0("chr", 1:22), plotType = c("ideogram", "labels"), ideogram.height = 0.03) } f2 = function() { circos.par(cell.padding = c(0, 0, 0, 0), gap.after = c(rep(1, nrow(tagments)-1), 10)) circos.genomicInitialize(tagments, plotType = NULL) circos.genomicTrack(DMR1, ylim = c(-0.6, 0.6), panel.fun = function(region, value, ...) { for(h in seq(-0.6, 0.6, by = 0.2)) { circos.lines(CELL_META$cell.xlim, c(h, h), lty = 3, col = "#AAAAAA") } circos.lines(CELL_META$cell.xlim, c(0, 0), lty = 3, col = "#888888") ``` -------------------------------- ### Set Global Layout Parameters with circos.par() Source: https://context7.com/jokergoo/circlize_book/llms.txt Configure global circular layout parameters like starting degree, sector gaps, and track height. Call before circos.initialize() for parameters affecting sector allocation. Supports options()-style assignment and a RESET keyword. ```R library(circlize) # Configure layout before initialization circos.par( start.degree = 90, # start at the top gap.after = c(a = 5, b = 5, c = 15), # named gaps track.height = 0.15, points.overflow.warning = FALSE, cell.padding = c(0.02, 1, 0.02, 1) ) # Inspect current values circos.par # prints table of all settings # Reset everything to defaults circos.par(RESET = TRUE) ``` -------------------------------- ### Create Tracks with Per-Cell Plotting using circos.track() and panel.fun Source: https://context7.com/jokergoo/circlize_book/llms.txt Create a new circular track and optionally run a user-defined panel.fun for per-cell plotting. panel.fun receives cell-specific data and can use low-level graphic functions. Examples include scatter plots, histograms, and connected lines. ```R # Initialize circos.initialize(sectors, x = x) # Track 1 — scatter plot with sector labels and axes circos.track(sectors, y = y, panel.fun = function(x, y) { # add sector label above the cell circos.text(CELL_META$xcenter, CELL_META$cell.ylim[2] + mm_y(5), CELL_META$sector.index, facing = "outside", niceFacing = TRUE, cex = 0.7) circos.axis(labels.cex = 0.5) circos.points(x, y, pch = 16, cex = 0.4, col = ifelse(y > 0.5, "#E41A1C", "#377EB8")) }) # Track 2 — histogram track (high-level, creates its own track) circos.trackHist(sectors, x, bin.size = 0.2, bg.col = rep(c("#EFEFEF","#CCCCCC"), 4), col = NA) # Track 3 — connected lines through random sample of points circos.track(sectors, x = x, y = y, panel.fun = function(x, y) { idx <- order(x)[seq(1, length(x), length.out = 15)] circos.lines(x[idx], y[idx], col = "#00000080", lwd = 1.5) }) circos.clear() ``` -------------------------------- ### Chord Diagram with Sector Reduction Source: https://github.com/jokergoo/circlize_book/blob/master/book/14-chord-diagram-simple.md Illustrates how small sectors, defined by the `reduce` argument (defaulting to removing sectors smaller than 1%% of the total size), are automatically removed from the chord diagram. This example sets specific rows/columns to tiny values to show their removal. ```r mat = matrix(rnorm(36), 6, 6) rownames(mat) = paste0("R", 1:6) colnames(mat) = paste0("C", 1:6) mat[2, ] = 1e-10 mat[, 3] = 1e-10 ``` ```r chordDiagram(mat) circos.info() ``` -------------------------------- ### Multiple Pre-allocated Tracks with Custom Settings Source: https://github.com/jokergoo/circlize_book/blob/master/book/15-chord-diagram-advanced-usage.md Illustrates how to pre-allocate multiple tracks, each with its own specific configuration, such as track height and background border color. ```r chordDiagram(mat, annotationTrack = NULL, preAllocateTracks = list(list(track.height = 0.1), list(bg.border = "black"))) ``` -------------------------------- ### Get cell metadata with get.cell.meta.data() Source: https://github.com/jokergoo/circlize_book/blob/master/book/02-circlize-layout.md Retrieve metadata for the current cell within panel.fun using get.cell.meta.data(). This function can take a specific metadata name or be used without arguments to get all available metadata. ```r get.cell.meta.data(name) get.cell.meta.data(name, sector.index, track.index) ``` -------------------------------- ### Initialize Gitbook Source: https://github.com/jokergoo/circlize_book/blob/master/book/advanced-layout.html This JavaScript snippet initializes Gitbook with specified configuration options for sharing, font settings, and search. ```javascript gitbook.require("gitbook", function(gitbook) { gitbook.start({"sharing": {"github": false, "facebook": true, "twitter": true, "linkedin": false, "weibo": false, "instapaper": false, "vk": false, "whatsapp": false, "all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]}, "fontsettings": {"theme": "white", "family": "sans", "size": 2}, "edit": {"link": "https://github.com/jokergoo/circlize_book/edit/master/07-advanced-usage.Rmd", "text": "Edit"}, "history": {"link": null, "text": null}, "view": {"link": null, "text": null}, "download": null, "search": {"engine": "fuse", "options": null}, "toc": {"collapse": "subsection"}}); }); ``` -------------------------------- ### Initialize Gitbook Source: https://github.com/jokergoo/circlize_book/blob/master/book/legends.html This JavaScript code initializes the Gitbook environment with specific configurations for sharing, font settings, and table of contents. ```javascript gitbook.require(["gitbook"], function(gitbook) { gitbook.start({ "sharing": { "github": false, "facebook": true, "twitter": true, "linkedin": false, "weibo": false, "instapaper": false, "vk": false, "whatsapp": false, "all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"] }, "fontsettings": { "theme": "white", "family": "sans", "size": 2 }, "edit": { "link": "https://github.com/jokergoo/circlize_book/edit/master/04-legends.Rmd", "text": "Edit" }, "history": { "link": null, "text": null }, "view": { "link": null, "text": null }, "download": null, "search": { "engine": "fuse", "options": null }, "toc": { "collapse": "subsection" } }); }); ``` -------------------------------- ### Set 'start.degree' for Genomic Plot Source: https://github.com/jokergoo/circlize_book/blob/master/book/initialize-genomic-plot.html Control the starting degree of the circular plot. Remember to call `circos.clear()` after setting parameters and before plotting. ```R circos.par("start.degree" = 90) circos.initializeWithIdeogram() circos.clear() text(0, 0, "'start.degree' = 90", cex = 1) ``` -------------------------------- ### Initialize and Draw Tracks in Circlize Source: https://github.com/jokergoo/circlize_book/blob/master/book/02-circlize-layout.md Use `circos.initialize` to set up sectors and `circos.track` to draw elements like points and lines within those sectors. Internal variables automatically manage the current sector and track context. ```R circos.initialize(sectors, xlim) circos.track(sectors, all_x, all_y, ylim, panel.fun = function(x, y) { circos.points(x, y) circos.lines(x, y) }) ``` -------------------------------- ### Initializing Gitbook Source: https://github.com/jokergoo/circlize_book/blob/master/book/make-fun-of-the-package.html This JavaScript code initializes Gitbook with specific configuration options for sharing, font settings, and table of contents. ```javascript gitbook.require(["gitbook"], function(gitbook) { gitbook.start({ "sharing": { "github": false, "facebook": true, "twitter": true, "linkedin": false, "weibo": false, "instapaper": false, "vk": false, "whatsapp": false, "all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"] }, "fontsettings": { "theme": "white", "family": "sans", "size": 2 }, "edit": { "link": "https://github.com/jokergoo/circlize_book/edit/master/17-make-fun.Rmd", "text": "Edit" }, "history": { "link": null, "text": null }, "view": { "link": null, "text": null }, "download": null, "search": { "engine": "fuse", "options": null }, "toc": { "collapse": "subsection" } }); }); ``` -------------------------------- ### Apply Custom Dendrogram Callback Source: https://github.com/jokergoo/circlize_book/blob/master/book/circos-heatmap.html Use a callback function with `dend.callback` to modify dendrograms after they are generated. This example reorders dendrograms using `dendsort`. ```R library(dendsort) circos.heatmap(mat1, split = split, col = col_fun1, dend.side = "inside", dend.callback = function(dend, m, si) { dendsort(dend) } ) ``` -------------------------------- ### Create Scaled Chord Diagrams for Comparison Source: https://github.com/jokergoo/circlize_book/blob/master/book/advanced-usage-of-chorddiagram-1.html Illustrates how to create two chord diagrams with consistent link scaling for comparison. The second diagram uses `calc_gap()` to adjust gaps for uniform link width. ```R mat1 = matrix(sample(20, 25, replace = TRUE), 5) chordDiagram(mat1, directional = 1, grid.col = rep(1:5, 2), transparency = 0.5, big.gap = 10, small.gap = 1) # 10 and 1 are default values for the two arguments mat2 = mat1 / 2 # calc_gap() can be used to calculate the gap for the second Chord diagram to make the scale of the two Chord diagram the same. ``` -------------------------------- ### Draw horizontal and vertical segments in a track Source: https://github.com/jokergoo/circlize_book/blob/master/book/03-graphics.md Example demonstrating drawing both horizontal and vertical segments within a circos track using `circos.segments()`. ```r circos.initialize(letters[1:8], xlim = c(0, 1)) circos.track(ylim = c(0, 1), track.height = 0.3, panel.fun = function(x, y) { x = seq(0.2, 0.8, by = 0.2) y = seq(0.2, 0.8, by = 0.2) circos.segments(x, 0.1, x, 0.9) circos.segments(0.1, y, 0.9, y) }) ``` -------------------------------- ### GitBook Initialization Source: https://github.com/jokergoo/circlize_book/blob/master/book/nested-zooming.html Initializes GitBook with specified sharing, font settings, and editing options. This is boilerplate code for GitBook integration. ```javascript gitbook.require(["gitbook"], function(gitbook) { gitbook.start({ "sharing": { "github": false, "facebook": true, "twitter": true, "linkedin": false, "weibo": false, "instapaper": false, "vk": false, "whatsapp": false, "all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"] }, "fontsettings": { "theme": "white", "family": "sans", "size": 2 }, "edit": { "link": "https://github.com/jokergoo/circlize_book/edit/master/13-nested-zooming.Rmd", "text": "Edit" }, "history": { "link": null, "text": null }, "view": { "link": null, "text": null }, "download": null, "search": { "engine": "fuse", "options": null }, "toc": { "collapse": "subsection" } }); }); ``` -------------------------------- ### Add Legend to Circular Heatmap Source: https://github.com/jokergoo/circlize_book/blob/master/book/circos-heatmap.html Demonstrates how to add a legend to a circular heatmap using the ComplexHeatmap package. Ensure ComplexHeatmap is installed and loaded. ```R library(ComplexHeatmap) lgd = Legend(title = "mat1", col_fun = col_fun1) grid.draw(lgd) ``` -------------------------------- ### Initialize Circos Layout with Sectors Source: https://github.com/jokergoo/circlize_book/blob/master/book/02-circlize-layout.md Use `circos.initialize()` to set up sectors. Data ranges can be specified via `x` or `xlim`. If `sectors` is omitted, `xlim` row names are used. ```r circos.initialize(sectors, x = x) circos.initialize(sectors, xlim = xlim) ``` ```r circos.initialize(xlim = xlim) ``` -------------------------------- ### Color Sub-Dendrograms without Splitting Source: https://github.com/jokergoo/circlize_book/blob/master/book/06-circos-heatmap.md Assigns different colors to sub-dendrograms when the matrix is not split. This example uses `color_branches()` with `k = 4` and a vector of colors. ```r circos.heatmap(mat1, col = col_fun1, dend.side = "inside", dend.track.height = 0.2, dend.callback = function(dend, m, si) { color_branches(dend, k = 4, col = 2:5) } ) ``` -------------------------------- ### Initialize with Ideogram and Zoomed Chromosomes Source: https://github.com/jokergoo/circlize_book/blob/master/book/09-initialize-genomic-data.md Initializes the circlize plot with chromosome ideograms, applying zooming to specified chromosomes. Sets the starting degree for the plot. ```r circos.par(start.degree = 90) circos.initializeWithIdeogram(extend_chromosomes(cytoband_df, c("chr1", "chr2")), sector.width = sector.width) ``` -------------------------------- ### Pre-allocate Multiple Tracks with Custom Settings Source: https://github.com/jokergoo/circlize_book/blob/master/book/advanced-usage-of-chorddiagram.html Specify `preAllocateTracks` as a list containing settings for each track when multiple tracks need to be pre-allocated. This enables distinct configurations for each track. ```R chordDiagram(mat, annotationTrack = NULL, preAllocateTracks = list(list(track.height = 0.1), list(bg.border = "black"))) ``` -------------------------------- ### Initialize Circlize plot and tracks Source: https://github.com/jokergoo/circlize_book/blob/master/book/03-graphics.md Initializes a circular plot with specified sectors and creates multiple tracks. This setup is necessary before highlighting specific regions. ```r sectors = letters[1:8] circos.initialize(sectors, xlim = c(0, 1)) for(i in 1:3) { circos.track(ylim = c(0, 1)) } circos.info(plot = TRUE) ``` -------------------------------- ### Prepare Data for Chord Diagram Source: https://github.com/jokergoo/circlize_book/blob/master/book/16-a-complex-example-with-chord-diagram.md Prepares matrices and color vectors for chord diagram visualization. Adjusts colors based on quantile values to highlight specific data points. ```r state_col2 = c(state_col, state_col) names(state_col2) = c(rownames(mat), colnames(mat)) colmat = rep(state_col2[rownames(mat)], n_states) colmat = rgb(t(col2rgb(colmat)), maxColorValue = 255) qati = quantile(mat, 0.7) colmat[mat > qati] = paste0(colmat[mat > qati], "A0") colmat[mat <= qati] = paste0(colmat[mat <= qati], "20") dim(colmat) = dim(mat) ``` -------------------------------- ### Initialize and Add Multiple Heatmap Tracks Source: https://github.com/jokergoo/circlize_book/blob/master/book/06-circos-heatmap.md Demonstrates adding two heatmap tracks. The first call initializes the layout, determining row order and splitting for subsequent tracks. Use `circos.clear()` to reset. ```r mat2 = mat1[sample(100, 100), ] col_fun2 = colorRamp2(c(-2, 0, 2), c("green", "white", "red")) circos.heatmap(mat1, split = split, col = col_fun1, dend.side = "outside") circos.heatmap(mat2, col = col_fun2) ``` ```r circos.clear() ``` -------------------------------- ### Get Sector and Track Information in Circlize Source: https://context7.com/jokergoo/circlize_book/llms.txt Use circos.info() to retrieve details about a specific sector and track. This function is useful for debugging or understanding the current plot state. ```R circos.info(sector.index = "b", track.index = 1) ``` -------------------------------- ### Chord Diagram with Scaling Enabled Source: https://github.com/jokergoo/circlize_book/blob/master/book/14-chord-diagram-simple.md Demonstrates how to use the `scale = TRUE` argument to make each sector represent the fraction of interaction relative to other sectors originating from it. This makes all sectors appear the same size. ```r set.seed(999) mat = matrix(sample(18, 18), 3, 6) rownames(mat) = paste0("S", 1:3) colnames(mat) = paste0("E", 1:6) grid.col = c(S1 = "red", S2 = "green", S3 = "blue", E1 = "grey", E2 = "grey", E3 = "grey", E4 = "grey", E5 = "grey", E6 = "grey") par(mfrow = c(1, 2)) chordDiagram(mat, grid.col = grid.col) title("Default") chordDiagram(mat, grid.col = grid.col, scale = TRUE) title("scale = TRUE") ``` -------------------------------- ### Chord Diagram with Big Arrows Source: https://github.com/jokergoo/circlize_book/blob/master/book/14-chord-diagram-simple.md Utilizes 'big.arrow' type for arrows, which is efficient for diagrams with many links. This example also uses 'diffHeight' for better visual distinction. ```r matx = matrix(rnorm(64), 8) chordDiagram(matx, directional = 1, direction.type = c("diffHeight", "arrows"), link.arr.type = "big.arrow") ``` -------------------------------- ### Pre-allocating Tracks in chordDiagram() Source: https://github.com/jokergoo/circlize_book/blob/master/book/15-chord-diagram-advanced-usage.md Shows how to pre-allocate empty tracks before drawing the chord diagram, which can be used for adding custom graphics later. Inspects the total number of tracks after pre-allocation. ```r chordDiagram(mat, preAllocateTracks = 2) circos.info() ``` -------------------------------- ### Initialize Circos Heatmap and Add Row Means Track Source: https://github.com/jokergoo/circlize_book/blob/master/book/06-circos-heatmap.md Initializes the Circos layout in advance using `circos.heatmap.initialize` before adding a track for row means. This is an alternative to the previous method when the track is the first one. ```r circos.heatmap.initialize(mat1, split = split) # This is the same as the previous example circos.track(ylim = range(row_mean), panel.fun = function(x, y) { y = row_mean[CELL_META$subset] y = y[CELL_META$row_order] circos.lines(CELL_META$cell.xlim, c(0, 0), lty = 2, col = "grey") circos.points(seq_along(y) - 0.5, y, col = ifelse(y > 0, "red", "blue")) }, cell.padding = c(0.02, 0, 0.02, 0)) circos.heatmap(mat1, col = col_fun1) # no need to specify 'split' here ``` -------------------------------- ### Customize Sector Labels with Pre-allocated Tracks Source: https://github.com/jokergoo/circlize_book/blob/master/book/advanced-usage-of-chorddiagram.html Customize sector labels by pre-allocating a track and then updating it with custom labels. This example shows how to add labels with clockwise facing. ```R chordDiagram(mat, grid.col = grid.col, annotationTrack = "grid", preAllocateTracks = list(track.height = max(strwidth(unlist(dimnames(mat)))))) # we go back to the first track and customize sector labels circos.track(track.index = 1, panel.fun = function(x, y) { circos.text(CELL_META$xcenter, CELL_META$ylim[1], CELL_META$sector.index, facing = "clockwise", niceFacing = TRUE, adj = c(0, 0.5)) }, bg.border = NA) # here set bg.border to NA is important ``` -------------------------------- ### Chord Diagram with Negative Height Difference Source: https://github.com/jokergoo/circlize_book/blob/master/book/14-chord-diagram-simple.md Demonstrates using a negative `diffHeight` value to make the start ends of links longer than the other ends, in conjunction with 'big.arrow' type. ```r chordDiagram(matx, directional = 1, direction.type = c("diffHeight", "arrows"), link.arr.type = "big.arrow", diffHeight = -mm_h(2)) ``` -------------------------------- ### Add Raster Image with Various Facings Source: https://github.com/jokergoo/circlize_book/blob/master/book/03-graphics.md Demonstrates adding a raster image with different facing options ('inside', 'outside', 'reverse.clockwise', 'clockwise', 'downward'). Image size should be specified with units (e.g., '1cm'). ```r library(png) image = system.file("extdata", "Rlogo.png", package = "circlize") image = as.raster(readPNG(image)) circos.par(start.degree = 90) circos.initialize(letters[1:5], xlim = c(0, 1)) all_facing_options = c("inside", "outside", "reverse.clockwise", "clockwise", "downward") circos.track(ylim = c(0, 1), panel.fun = function(x, y) { circos.raster(image, CELL_META$xcenter, CELL_META$ycenter, width = "1cm", facing = all_facing_options[CELL_META$sector.numeric.index]) circos.text(CELL_META$xcenter, CELL_META$ycenter, all_facing_options[CELL_META$sector.numeric.index], facing = "inside", niceFacing = TRUE) }) ``` ```r circos.clear() ``` -------------------------------- ### Orient Chord Diagram Vertically Symmetric Source: https://github.com/jokergoo/circlize_book/blob/master/book/15-chord-diagram-advanced-usage.md Sets the starting degree for the Chord diagram to 90 and adds a vertical dotted line. This is useful for achieving vertical symmetry. ```R circos.par(start.degree = 90) chordDiagram(mat, grid.col = grid.col, big.gap = 20) abline(v = 0, lty = 2, col = "#00000080") ``` -------------------------------- ### circos.initialize() Source: https://context7.com/jokergoo/circlize_book/llms.txt Defines the sectors (categories) and their widths on the circle. The width of each sector is proportional to the data range in the x-direction for that category. Sector order follows the level order of the input factor. ```APIDOC ## circos.initialize() ### Description Defines the sectors (categories) and their widths on the circle. The width of each sector is proportional to the data range in the x-direction for that category. Sector order follows the level order of the input factor. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```r set.seed(999) n <- 1000 sectors <- sample(letters[1:8], n, replace = TRUE) x <- rnorm(n) y <- runif(n) circos.par("track.height" = 0.1) # Initialize from raw data vectors (x-ranges auto-computed per sector) circos.initialize(sectors, x = x) # --- OR --- specify xlim directly as a matrix (one row per sector) xlim <- cbind(rep(0, 8), runif(8, 0.5, 1.5)) rownames(xlim) <- letters[1:8] circos.initialize(xlim = xlim) # Control sector ordering via factor levels ordered_sectors <- factor(sectors, levels = letters[8:1]) circos.initialize(ordered_sectors, x = x) ``` ### Response #### Success Response (200) None explicitly defined, but initializes the circular layout. #### Response Example None ``` -------------------------------- ### Orient Chord Diagram Horizontally Symmetric Source: https://github.com/jokergoo/circlize_book/blob/master/book/15-chord-diagram-advanced-usage.md Sets the starting degree for the Chord diagram to 0 and adds a horizontal dotted line. This is useful for achieving horizontal symmetry. ```R par(mfrow = c(1, 2)) circos.par(start.degree = 0) chordDiagram(mat, grid.col = grid.col, big.gap = 20) abline(h = 0, lty = 2, col = "#00000080") circos.clear() ``` -------------------------------- ### Initialize Sectors on the Circle with circos.initialize() Source: https://context7.com/jokergoo/circlize_book/llms.txt Define sectors and their widths on the circle. Sector width is proportional to the x-direction data range for each category. Sector order follows factor level order. Can initialize from raw data vectors or by specifying xlim directly. ```R set.seed(999) n <- 1000 sectors <- sample(letters[1:8], n, replace = TRUE) x <- rnorm(n) y <- runif(n) circos.par("track.height" = 0.1) # Initialize from raw data vectors (x-ranges auto-computed per sector) circos.initialize(sectors, x = x) # --- OR --- specify xlim directly as a matrix (one row per sector) xlim <- cbind(rep(0, 8), runif(8, 0.5, 1.5)) rownames(xlim) <- letters[1:8] circos.initialize(xlim = xlim) # Control sector ordering via factor levels ordered_sectors <- factor(sectors, levels = letters[8:1]) circos.initialize(ordered_sectors, x = x) ``` -------------------------------- ### Create Circular Heatmap Tracks Source: https://github.com/jokergoo/circlize_book/blob/master/book/circos-heatmap.html Generates multiple circular heatmap tracks with different color mappings and track heights. This example visualizes various genomic data types. ```R col_meth = colorRamp2(c(0, 0.5, 1), c("blue", "white", "red")) circos.heatmap(mat_meth, split = km, col = col_meth, track.height = 0.12) col_direction = c("hyper" = "red", "hypo" = "blue") circos.heatmap(direction, col = col_direction, track.height = 0.01) col_expr = colorRamp2(c(-2, 0, 2), c("green", "white", "red")) circos.heatmap(mat_expr, col = col_expr, track.height = 0.12) col_pvalue = colorRamp2(c(0, 2, 4), c("white", "white", "red")) circos.heatmap(cor_pvalue, col = col_pvalue, track.height = 0.01) library(RColorBrewer) col_gene_type = structure(brewer.pal(length(unique(gene_type)), "Set3"), names = unique(gene_type)) circos.heatmap(gene_type, col = col_gene_type, track.height = 0.01) col_anno_gene = structure(brewer.pal(length(unique(anno_gene)), "Set1"), names = unique(anno_gene)) circos.heatmap(anno_gene, col = col_anno_gene, track.height = 0.01) col_dist = colorRamp2(c(0, 10000), c("black", "white")) circos.heatmap(dist, col = col_dist, track.height = 0.01) col_enhancer = colorRamp2(c(0, 1), c("white", "orange")) ``` -------------------------------- ### Create Ba-Gua and Tai-Ji Visualization Source: https://github.com/jokergoo/circlize_book/blob/master/book/make-fun-of-the-package.html Initializes circos for 8 sectors and draws Ba-Gua and Tai-Ji symbols using custom functions for yin and yang lines. Useful for representing dualistic concepts or complex symbolic systems. ```R sectors = 1:8 circos.par(start.degree = 22.5, gap.degree = 6) circos.initialize(sectors, xlim = c(0, 1)) # yang yao is __ (a long segment) add_yang_yao = function() { circos.rect(0,0,1,1, col = "black") } # yin yao is -- (two short segments) add_yin_yao = function() { circos.rect(0,0,0.45,1, col = "black") circos.rect(0.55,0,1,1, col = "black") } circos.track(ylim = c(0, 1), sectors = sectors, bg.border = NA, panel.fun = function(x, y) { i = get.cell.meta.data("sector.numeric.index") if(i %in% c(2, 5, 7, 8)) add_yang_yao() else add_yin_yao() }, track.height = 0.1) circos.track(ylim = c(0, 1), sectors = sectors, bg.border = NA, panel.fun = function(x, y) { i = get.cell.meta.data("sector.numeric.index") if(i %in% c(1, 6, 7, 8)) add_yang_yao() else add_yin_yao() }, track.height = 0.1) circos.track(ylim = c(0, 1), sectors = sectors, bg.border = NA, panel.fun = function(x, y) { i = get.cell.meta.data("sector.numeric.index") if(i %in% c(4, 5, 6, 7)) add_yang_yao() else add_yin_yao() }, track.height = 0.1) # the bottom of the most recent track r = get.cell.meta.data("cell.bottom.radius") - 0.1 # draw taiji, note default order is clock wise for `draw.sector` draw.sector(center = c(0, 0), start.degree = 90, end.degree = -90, rou1 = r, col = "black", border = "black") draw.sector(center = c(0, 0), start.degree = 270, end.degree = 90, ``` -------------------------------- ### Genomic Plotting Functions in Circlize Source: https://github.com/jokergoo/circlize_book/blob/master/book/genomic-introduction.html These are low-level functions for adding graphical elements to genomic tracks. They are designed to work with genomic regions defined by category, start, and end positions. ```R circos.genomicTrack() circos.genomicPoints() circos.genomicLines() circos.genomicRect() circos.genomicText() circos.genomicLink() ``` -------------------------------- ### Initialize sectors with data range Source: https://github.com/jokergoo/circlize_book/blob/master/book/circular-layout.html Initializes sectors with data ranges specified by a numeric vector `x`. The data ranges are calculated internally for each sector. ```R circos.initialize(sectors, x = x) ``` -------------------------------- ### Create Gene Type Heatmap Track Source: https://github.com/jokergoo/circlize_book/blob/master/book/06-circos-heatmap.md Visualizes gene types using a categorical color scale generated from the Set3 palette. Each unique gene type gets a distinct color. ```r library(RColorBrewer) col_gene_type = structure(brewer.pal(length(unique(gene_type)), "Set3"), names = unique(gene_type)) circos.heatmap(gene_type, col = col_gene_type, track.height = 0.01) ``` -------------------------------- ### Initialize sectors with explicit x-axis limits Source: https://github.com/jokergoo/circlize_book/blob/master/book/circular-layout.html Initializes sectors with explicit x-axis limits defined by a two-column matrix `xlim`. Each row corresponds to a sector. ```R circos.initialize(sectors, xlim = xlim) ``` -------------------------------- ### Create a Dartboard Visualization Source: https://github.com/jokergoo/circlize_book/blob/master/book/make-fun-of-the-package.html Initializes circos parameters, tracks, and adds text labels for a dartboard visualization. Use when precise control over track dimensions and background colors is needed. ```R sectors = 1:20 circos.par(gap.degree = 0, cell.padding = c(0, 0, 0, 0), start.degree = 360/20/2, track.margin = c(0, 0), clock.wise = FALSE) circos.initialize(sectors, xlim = c(0, 1)) circos.track(ylim = c(0, 1), sectors = sectors, bg.col = "black", track.height = 0.15) circos.trackText(x = rep(0.5, 20), y = rep(0.5, 20), labels = c(13, 4, 18, 1, 20, 5, 12, 9, 14, 11, 8, 16, 7, 19, 3, 17, 2, 15, 10, 6), cex = 0.8, sectors = sectors, col = "#EEEEEE", font = 2, facing = "downward") circos.track(ylim = c(0, 1), sectors = sectors, bg.col = rep(c("#E41A1C", "#4DAF4A"), 10), bg.border = "#EEEEEE", track.height = 0.05) circos.track(ylim = c(0, 1), sectors = sectors, bg.col = rep(c("black", "white"), 10), bg.border = "#EEEEEE", track.height = 0.275) circos.track(ylim = c(0, 1), sectors = sectors, bg.col = rep(c("#E41A1C", "#4DAF4A"), 10), bg.border = "#EEEEEE", track.height = 0.05) circos.track(ylim = c(0, 1), sectors = sectors, bg.col = rep(c("black", "white"), 10), bg.border = "#EEEEEE", track.height = 0.375) draw.sector(center = c(0, 0), start.degree = 0, end.degree = 360, rou1 = 0.1, col = "#4DAF4A", border = "#EEEEEE") draw.sector(center = c(0, 0), start.degree = 0, end.degree = 360, rou1 = 0.05, col = "#E41A1C", border = "#EEEEEE") circos.clear() ``` -------------------------------- ### Plot Transcripts for Genes in Circular Layout Source: https://github.com/jokergoo/circlize_book/blob/master/book/initialize-genomic-plot.html Initialize a circular plot with gene transcript data and then create tracks to visualize these transcripts. This example demonstrates plotting multiple transcripts per gene. ```R tp_family = readRDS(system.file(package = "circlize", "extdata", "tp_family_df.rds")) head(tp_family) circos.genomicInitialize(tp_family) circos.track(ylim = c(0, 1), bg.col = c("#FF000040", "#00FF0040", "#0000FF40"), bg.border = NA, track.height = 0.05) n = max(tapply(tp_family$transcript, tp_family$gene, function(x) length(unique(x)))) circos.genomicTrack(tp_family, ylim = c(0.5, n + 0.5), panel.fun = function(region, value, ...) { all_tx = unique(value$transcript) for(i in seq_along(all_tx)) { l = value$transcript == all_tx[i] # for each transcript current_tx_start = min(region[l, 1]) current_tx_end = max(region[l, 2]) circos.lines(c(current_tx_start, current_tx_end), c(n - i + 1, n - i + 1), col = "#CCCCCC") circos.genomicRect(region[l, , drop = FALSE], ytop = n - i + 1 + 0.4, ybottom = n - i + 1 - 0.4, col = "orange", border = NA) } }) ``` -------------------------------- ### Highlight sectors and tracks using helper function Source: https://github.com/jokergoo/circlize_book/blob/master/book/graphics.html Demonstrates the use of `highlight.sector` for easily highlighting complete cells by specifying sector and track indices. It also mentions the `padding` argument for adjusting highlighted region size and the ability to add text. ```R sectors = letters[1:8] ``` -------------------------------- ### Add Genomic Labels Outside Track Source: https://github.com/jokergoo/circlize_book/blob/master/book/high-level-genomic-functions.html Places genomic labels outside the normal genomic track. This example customizes label and line colors based on the first column of the bed data. ```R circos.initializeWithIdeogram(plotType = NULL) circos.genomicLabels(bed, labels.column = 4, side = "outside", col = as.numeric(factor(bed[[1]])), line_col = as.numeric(factor(bed[[1]]))) circos.genomicIdeogram() circos.clear() ``` -------------------------------- ### Customizing Annotation Tracks in chordDiagram() Source: https://github.com/jokergoo/circlize_book/blob/master/book/15-chord-diagram-advanced-usage.md Demonstrates how to control which annotation tracks are displayed (e.g., 'grid', 'name') and their respective heights using the annotationTrack and annotationTrackHeight arguments. ```r chordDiagram(mat, grid.col = grid.col, annotationTrack = "grid") ``` ```r chordDiagram(mat, grid.col = grid.col, annotationTrack = c("name", "grid"), annotationTrackHeight = c(0.03, 0.01)) ``` ```r chordDiagram(mat, grid.col = grid.col, annotationTrack = NULL) ``` -------------------------------- ### Handle Sector Labels in Narrow Sectors Source: https://github.com/jokergoo/circlize_book/blob/master/book/advanced-usage-of-chorddiagram-1.html For sectors narrower than 20 degrees, labels are automatically added in a radial direction. This example demonstrates setting up a chord diagram with potentially narrow sectors. ```R set.seed(123) mat2 = matrix(rnorm(100), 10) chordDiagram(mat2, annotationTrack = "grid", preAllocateTracks = list(track.height = max(strwidth(unlist(dimnames(mat)))))) circos.track(track.index = 1, panel.fun = function(x, y) { ``` -------------------------------- ### Overwriting Pre-allocated Track Settings Source: https://github.com/jokergoo/circlize_book/blob/master/book/15-chord-diagram-advanced-usage.md Demonstrates how to customize the settings of pre-allocated tracks by providing a list of parameters, such as setting a specific track height. ```r chordDiagram(mat, annotationTrack = NULL, preAllocateTracks = list(track.height = 0.3)) ``` -------------------------------- ### Manual Heatmap Layout Initialization Source: https://github.com/jokergoo/circlize_book/blob/master/book/06-circos-heatmap.md Manually initializes the heatmap layout using `circos.heatmap.initialize()` with a specified matrix, allowing control over which matrix determines the global layout. Subsequent `circos.heatmap()` calls share this layout. Use `circos.clear()` to reset. ```r circos.heatmap.initialize(mat1, split = split) circos.heatmap(mat2, col = col_fun2, dend.side = "outside") circos.heatmap(mat1, col = col_fun1) ``` ```r circos.clear() ``` -------------------------------- ### Initialize Circos with Ideogram Source: https://github.com/jokergoo/circlize_book/blob/master/book/11-modes-of-input.md Sets up the circos plotting environment with specific track height, start degree, canvas limits, gap degree, and cell padding. Initializes the ideogram for chromosome 1. ```r circos.par("track.height" = 0.08, start.degree = 90, canvas.xlim = c(0, 1), canvas.ylim = c(0, 1), gap.degree = 270, cell.padding = c(0, 0, 0, 0)) circos.initializeWithIdeogram(chromosome.index = "chr1", plotType = NULL) ``` -------------------------------- ### Create Distance to TSS Heatmap Track Source: https://github.com/jokergoo/circlize_book/blob/master/book/06-circos-heatmap.md Generates a heatmap track for the distance of differentially methylated regions (DMRs) to the transcription start site (TSS). Uses a black-white color scale for distances up to 10000. ```r col_dist = colorRamp2(c(0, 10000), c("black", "white")) circos.heatmap(dist, col = col_dist, track.height = 0.01) ```