Skip to content

Commit

Permalink
support nicer Chord diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
jokergoo committed Jun 23, 2020
1 parent 092e434 commit 9769ad7
Show file tree
Hide file tree
Showing 81 changed files with 1,350 additions and 1,024 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: circlize
Type: Package
Title: Circular Visualization
Version: 0.4.10
Version: 0.4.11
Date: 2020-06-14
Author: Zuguang Gu
Maintainer: Zuguang Gu <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export("print.CELL_META")
export("CELL_META")
export("add_transparency")
export("adjacencyList2Matrix")
export("adjacencyMatrix2List")
export("calc_gap")
export("chordDiagram")
export("chordDiagramFromDataFrame")
Expand Down
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Changes in version 0.4.11
-----------------------------------------------------------------------
* `chordDiagram()`: add `link.auto` argument
* `chordDiagram()`: add `link.target.prop` and `target.prop.height` arguments

Changes in version 0.4.10
-----------------------------------------------------------------------
* `highlight.sector()`: fixed a bug when circos.par("clock.wise" = FALSE)
Expand Down
164 changes: 129 additions & 35 deletions R/chordDiagram.R

Large diffs are not rendered by default.

65 changes: 41 additions & 24 deletions R/circos.arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
# Draw arrow which is paralle to the circle
#
# == param
# -x1 start position of the arrow on the x-axis.
# -x2 end position of the arrow on the x-axis.
# -y position of the arrow on the y-axis. Note this is the center of the arrow on y-axis.
# -width width of the arrow body.
# -sector.index index of the sector.
# -track.index index of the track.
# -arrow.head.length length of the arrow head. Note the value should be smaller than the length of the arrow itself (which is ``x2 - x1``).
# -arrow.head.width width of the arrow head.
# -arrow.position where is the arrow head on the arrow.
# -tail the shape of the arrow tail (the opposite side of arrow head).
# -border border color of the arrow.
# -col filled color of the arrow.
# -lty line style of the arrow.
# -... pass to `graphics::polygon`.
# -x1 Start position of the arrow on the x-axis.
# -x2 End position of the arrow on the x-axis. Note ``x2`` should be larger than ``x1``. The direction
# of arrows can be controlled by ``arrow.position`` argument.
# -y Position of the arrow on the y-axis. Note this is the center of the arrow on y-axis.
# -width Width of the arrow body.
# -sector.index Index of the sector.
# -track.index Index of the track.
# -arrow.head.length Length of the arrow head. Note the value should be smaller than the length of the arrow itself (which is ``x2 - x1``).
# -arrow.head.width Width of the arrow head.
# -arrow.position Where is the arrow head on the arrow. If you want to the arrow in the reversed direction, set this value to ``"start"``.
# -tail The shape of the arrow tail (the opposite side of arrow head).
# -border Border color of the arrow.
# -col Filled color of the arrow.
# -lty Line style of the arrow.
# -... Pass to `graphics::polygon`.
#
# == details
# Note all position values are measured in the data coordinate (the coordinate in each cell).
# Note all position values are measured in the data coordinate (the coordinate in each cell). For the values of
# ``width``, ``arrow.head.Length``, ``arrow.head.width``, they can be set with `mm_y`/`cm_y`/`inches_y` in absolute units.
#
# If you see points overflow warnings, you can set ``circos.par(points.overflow.warning = FALSE)`` to turn it off.
#
Expand All @@ -30,14 +32,30 @@
# Zuguang Gu <[email protected]>
#
# == example
# op = par(no.readonly = TRUE)
# par(mfrow = c(1, 2))
# circos.initialize(letters[1:4], xlim = c(0, 1))
# col = rand_color(4)
# tail = c("point", "normal", "point", "normal")
# circos.track(ylim = c(0, 1), panel.fun = function(x, y) {
# circos.arrow(0, 1, y = 0.5, width = 0.4, arrow.head.length = ux(1, "cm"),
# col = "red", tail = ifelse(CELL_META$sector.index \%in\% c("a", "c"),
# "point", "normal"))
# circos.arrow(x1 = 0, x2 = 1, y = 0.5, width = 0.4,
# arrow.head.width = 0.6, arrow.head.length = cm_x(1),
# col = col[CELL_META$sector.numeric.index],
# tail = tail[CELL_META$sector.numeric.index])
# }, bg.border = NA, track.height = 0.4)
# circos.clear()
#
# circos.initialize(letters[1:4], xlim = c(0, 1))
# tail = c("point", "normal", "point", "normal")
# circos.track(ylim = c(0, 1), panel.fun = function(x, y) {
# circos.arrow(x1 = 0, x2 = 1, y = 0.5, width = 0.4,
# arrow.head.width = 0.6, arrow.head.length = cm_x(1),
# col = col[CELL_META$sector.numeric.index],
# tail = tail[CELL_META$sector.numeric.index],
# arrow.position = "start")
# }, bg.border = NA, track.height = 0.4)
# par(op)
#
# ########## cell cycle ###########
# cell_cycle = data.frame(phase = factor(c("G1", "S", "G2", "M"),
# levels = c("G1", "S", "G2", "M")),
Expand All @@ -47,7 +65,7 @@
# circos.initialize(cell_cycle$phase, xlim = cbind(rep(0, 4), cell_cycle$hour))
# circos.track(ylim = c(0, 1), panel.fun = function(x, y) {
# circos.arrow(CELL_META$xlim[1], CELL_META$xlim[2],
# arrow.head.width = CELL_META$yrange*0.8, arrow.head.length = ux(1, "cm"),
# arrow.head.width = CELL_META$yrange*0.8, arrow.head.length = cm_x(1),
# col = color[CELL_META$sector.numeric.index])
# circos.text(CELL_META$xcenter, CELL_META$ycenter, CELL_META$sector.index,
# facing = "downward")
Expand All @@ -57,11 +75,11 @@
circos.arrow = function(
x1,
x2,
y = get.cell.meta.data("ycenter", sector.index, track.index),
width = get.cell.meta.data("yrange", sector.index, track.index)/2,
y = get.cell.meta.data("ycenter"),
width = get.cell.meta.data("yrange")/2,
sector.index = get.current.sector.index(),
track.index = get.current.track.index(),
arrow.head.length = convert_x(5, "mm", sector.index, track.index),
arrow.head.length = mm_x(5),
arrow.head.width = width*2,
arrow.position = c("end", "start"),
tail = c("normal", "point"),
Expand All @@ -73,8 +91,7 @@ circos.arrow = function(
arrow.position = match.arg(arrow.position)[1]
tail = match.arg(tail)[1]

sector.index = sector.index
track.index = track.index
set.current.cell(sector.index, track.index)

if(x2 <= x1) {
stop_wrap("`x2` should be larger than `x1`. Set `arrow.position = 'start'`\nto get reverse clockwise arrows.")
Expand Down
6 changes: 6 additions & 0 deletions R/circos.heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ is.circos.heatmap.cached = function() {
# -distance.method Distance method, pass to `stats::dist`.
# -dend.callback A callback function that is applied to the dendrogram in every sector.
#
# == seealso
# https://jokergoo.github.io/2020/05/21/make-circular-heatmaps/
#
circos.heatmap.initialize = function(mat, split = NULL, cluster = TRUE,
clustering.method = "complete", distance.method = "euclidean",
dend.callback = function(dend, m, si) reorder(dend, rowMeans(m))) {
Expand Down Expand Up @@ -185,6 +188,9 @@ circos.heatmap.validate = function(mat_list) {
# -show.sector.labels Whether to show sector labels.
# -... Pass to `circos.track` which draws the heatmap track.
#
# == seealso
# https://jokergoo.github.io/2020/05/21/make-circular-heatmaps/
#
# == example
# \donttest{
# set.seed(123)
Expand Down
18 changes: 9 additions & 9 deletions R/circos.nested.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
# Nested zooming with two circular plots
#
# == param
# -f1 a self-defined function for making the first circular plot. The function should have no argument.
# -f2 a self-defined function for making the second circular plot. The function should have no argument.
# -correspondance a six-column data frame which contains correspondance between the
# -f1 A self-defined function for making the first circular plot. The function should have no argument.
# -f2 A self-defined function for making the second circular plot. The function should have no argument.
# -correspondance A six-column data frame which contains correspondance between the
# coordinates in two circular plots
# -connection_height the height of the connection track, measured as the percent to the radius of the unit circle.
# -connection_height The height of the connection track, measured as the percent to the radius of the unit circle.
# The value can be specified by `uh` or `convert_height` with absolute units.
# -connection_col filled color of the connection track. The value can be a vector with same length as number of rows of ``correspondance``
# -connection_border border color of the connection track.
# -connection_lty line style of the connection track borders
# -connection_lwd line width of the connection track borders
# -connection_col Filled color of the connection track. The value can be a vector with same length as number of rows of ``correspondance``
# -connection_border Border color of the connection track.
# -connection_lty Line style of the connection track borders
# -connection_lwd Line width of the connection track borders
# -adjust_start_degree If ``circos.par(start.degree = ...)`` is not set in ``f2()``, the start degree for the second
# circular plot will be adjusted to make the distance of sectors between the two plots to the minimal.
#
Expand All @@ -38,7 +38,7 @@ circos.nested = function(
f1,
f2,
correspondance,
connection_height = convert_height(5, "mm"),
connection_height = mm_h(5),
connection_col = NA,
connection_border = "black",
connection_lty = par("lty"),
Expand Down
Loading

0 comments on commit 9769ad7

Please sign in to comment.